2016-07-12 19:05:56 +00:00
|
|
|
#lang syndicate/actor
|
2016-05-27 23:43:35 +00:00
|
|
|
|
2016-07-12 19:05:56 +00:00
|
|
|
(require/activate syndicate/drivers/timer)
|
|
|
|
(require/activate syndicate/drivers/udp)
|
2016-05-27 23:43:35 +00:00
|
|
|
(require racket/random file/sha1)
|
|
|
|
|
2016-05-28 14:32:03 +00:00
|
|
|
;; IANA offers guidelines for choosing multicast addresses [1].
|
|
|
|
;;
|
|
|
|
;; Reasonable candidates for local experimentation include:
|
|
|
|
;; - 224.0.1.20, "any private experiment"
|
|
|
|
;; - 233.252.0.0 - 233.252.0.255, "MCAST-TEST-NET", for examples and documentation (only)
|
|
|
|
;;
|
|
|
|
;; For production and semi-production use, registering an address may
|
|
|
|
;; be an option; failing that, the Administratively Scoped Block
|
|
|
|
;; (239/8; see RFC 2365) may be used:
|
|
|
|
;; - 239.255.0.0 - 239.255.255.255, "IPv4 Local Scope"
|
|
|
|
;; - 239.192.0.0 - 239.195.255.255, "Organization Local Scope"
|
|
|
|
;;
|
|
|
|
;; [1] http://www.iana.org/assignments/multicast-addresses/
|
|
|
|
|
|
|
|
(define group-address "233.252.0.101") ;; falls within MCAST-TEST-NET
|
|
|
|
(define group-port 5999) ;; make sure your firewall is open to UDP on this port
|
|
|
|
|
2017-02-15 23:18:19 +00:00
|
|
|
(spawn (define me (bytes->hex-string (crypto-random-bytes 8)))
|
2016-05-28 14:32:03 +00:00
|
|
|
(define h (udp-listener group-port))
|
2016-05-27 23:43:35 +00:00
|
|
|
|
|
|
|
(define (rearm!) (send! (set-timer h 1000 'relative)))
|
|
|
|
|
2016-08-24 16:35:38 +00:00
|
|
|
(on-start (rearm!))
|
2016-05-27 23:43:35 +00:00
|
|
|
|
2016-08-24 16:35:38 +00:00
|
|
|
(assert (udp-multicast-group-member h group-address #f))
|
|
|
|
(assert (udp-multicast-loopback h #t))
|
|
|
|
(on (message (udp-packet $source h $body))
|
|
|
|
(printf "~a: ~a\n" source body))
|
|
|
|
(on (message (timer-expired h $now))
|
|
|
|
(rearm!)
|
|
|
|
(send! (udp-packet h
|
|
|
|
(udp-remote-address group-address group-port)
|
|
|
|
(string->bytes/utf-8 (format "~a ~a" me now))))))
|