Add a UDP example

This commit is contained in:
Quentin 2020-07-09 10:03:55 +02:00
parent 9536b0affa
commit e1cf9a35b5
1 changed files with 18 additions and 0 deletions

18
examples/udp_server.scm Normal file
View File

@ -0,0 +1,18 @@
(load "../bindings/libc.scm")
(define (check-err ret msg)
(cond
((< ret 0)
(perror msg)
(raise msg))
(#t ret)))
(define (udp-sock fx)
(fx
(check-err
(socket 'AF_INET 'SOCK_DGRAM 'IPPROTO_NONE)
"Unable to init UDP socket")))
(udp-sock
(lambda (s)
(printf "~a~%" s)))