| 1 | (use socket) |
|---|
| 2 | (set! *socket* (socket af/inet sock/dgram )) |
|---|
| 3 | (set! (so-reuse-address? *socket*) #t) |
|---|
| 4 | (socket-bind *socket* (inet-address "0.0.0.0" 5055)) |
|---|
| 5 | ;; (socket-receive ..) here blocks the prints below |
|---|
| 6 | ;; after 1 s (about 10 hello's) |
|---|
| 7 | (thread-start! (lambda () |
|---|
| 8 | (thread-sleep! 1) |
|---|
| 9 | (print "receiving ...") |
|---|
| 10 | (print (socket-receive *socket* 1024)) |
|---|
| 11 | (print "done"))) |
|---|
| 12 | |
|---|
| 13 | (let loop () |
|---|
| 14 | (print "hello from main-thread!") |
|---|
| 15 | (thread-sleep! .1) |
|---|
| 16 | (loop)) |
|---|
| 17 | |
|---|
| 18 | ;; the hello's from the main thread continue after sending a udp packet: |
|---|
| 19 | ;; $ echo test `date` | socat - UDP-DATAGRAM:127.0.0.1:5055,broadcast |
|---|