schemelib/examples/udp_server.scm

18 lines
551 B
Scheme
Raw Normal View History

2020-07-10 08:35:38 +00:00
(load "../io/udpsock.scm")
2020-07-09 14:20:59 +00:00
(load "../bindings/utils.scm")
2020-07-09 10:51:53 +00:00
2020-07-09 10:15:00 +00:00
(udpsock-create
2020-07-09 10:51:53 +00:00
(lambda (sock)
(udpsock-reuseaddr sock)
2020-07-09 15:51:13 +00:00
(udpsock-bind sock "127.0.0.8" 1337)
2020-07-10 08:32:46 +00:00
(udpsock-io
2020-07-09 13:59:25 +00:00
sock
2020-07-10 08:32:46 +00:00
(lambda (host port buf nread send)
(let* ([charbuf (make-ftype-pointer char buf)]
[udpmsg (char*->string charbuf nread)])
(printf
"host: ~a, port: ~a, nread: ~a, buf: ~a~%"
host port nread udpmsg)
(send host port (ftype-pointer-address (string->char* udpmsg charbuf nread)) nread)
)))))