Distributed programming: Difference between revisions

(→‎Socket, Plain Text: changed the code to make it satisfy the task description)
Line 1,188:
conn.multicast(spread.RELIABLE_MESS, 'test', 'hello, this is message sent from python')
conn.disconnect()</lang>
 
=={{header|Racket}}==
Server and client in the same piece of code, running a useless (fib 42) computation, four times, on four hosts (which all happen to be "localhost", but that can change, of course).
 
<lang racket>
#lang racket/base
(require racket/place/distributed racket/place)
 
(define (fib n)
(if (<= n 1) n (+ (fib (- n 1)) (fib (- n 2)))))
 
(provide work)
(define (work)
(place ch
(place-channel-put ch (fib (place-channel-get ch)))))
 
(module+ main
(define places
(for/list ([host '("localhost" "localhost" "localhost" "localhost")]
[port (in-naturals 12345)])
(define-values [node place]
(spawn-node-supervise-place-at host #:listen-port port #:thunk #t
(quote-module-path "..") 'work))
place))
(message-router
(after-seconds 1
(for ([p places]) (*channel-put p 42))
(printf "Results: ~s\n" (map *channel-get places))
(exit))))
</lang>
 
=={{header|Ruby}}==