Skip to content

Instantly share code, notes, and snippets.

@AiziChen
Last active April 17, 2022 10:18
Show Gist options
  • Save AiziChen/acb42dcb0d04c9dfd957210350a9e8a7 to your computer and use it in GitHub Desktop.
Save AiziChen/acb42dcb0d04c9dfd957210350a9e8a7 to your computer and use it in GitHub Desktop.
UDP server/client and synchronize event
#lang racket/base
(require racket/udp)
(define udp (udp-open-socket))
(udp-send-to udp "ip-address" 12345 #"hello")
#lang racket/base
(require racket/udp)
(define udp (udp-open-socket))
(udp-bind! udp "0.0.0.0" 12345)
(define bs (make-bytes 1024))
(let loop ()
(sync (handle-evt
(udp-receive!-evt udp bs)
(lambda (rs)
(displayln (subbytes bs 0 (car rs))))))
(loop))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment