haskell - Listen on TCP and UDP on the same port -
how can haskell listen udp , tcp on same port?
here code have far (based on acme-http):
listenon portm = prototcp <- getprotocolnumber "tcp" e.bracketonerror (socket af_inet stream prototcp) sclose (\sock -> setsocketoption sock reuseaddr 1 setsocketoption sock nodelay 1 bindsocket sock (sockaddrinet (fromintegral portm) inaddr_any) listen sock (max 1024 maxlistenqueue) return sock ) protoudp <- getprotocolnumber "udp" e.bracketonerror (socket af_inet datagram protoudp) sclose (\sock -> setsocketoption sock reuseaddr 1 bindsocket sock (sockaddrinet (fromintegral portm) inaddr_any) return sock )
i compiles fine, follow runtime error:
user error (accept: can't perform accept on socket ((af_inet,datagram,17)) in status bound)
unfortunately, documentation on network programming in haskell bit limited (as usual). don't know i'm supposed figure stuff out.
[update]
interested, here result:
https://github.com/joehillen/acme-sip/blob/master/acme/serve.hs
i realize there lot of room improvement, works.
there doesn't seem wrong code, somewhere else code seems calling accept()
on udp socket, isn't legal. need udp socket receive , send it.
Comments
Post a Comment