[Haskell-beginners] listenOn specific IP
voldermort at hotmail.com
Tue Jul 30 15:49:15 CEST 2013
vold <voldermort <at> hotmail.com> writes:
> I'm trying to write a simple server with network. listenOn takes a
> socket number, but tries to bind to every available IP, which isn't what I
> need. How do I tell it to bind to a specific address?
I did this eventually by writing my own copy of the listenOn function
listenOn' host (PortNumber port) = do
proto <- getProtocolNumber "tcp"
(socket AF_INET Stream proto)
(\sock -> do
setSocketOption sock ReuseAddr 1
bindSocket sock (SockAddrInet port host)
listen sock maxListenQueue
It feels very hacky though.
More information about the Beginners