[Haskell-cafe] Sockets get bound to wrong port on Windows
Matthias Reisner
matthias.reisner at googlemail.com
Wed Jun 2 23:56:06 EDT 2010
Am 03.06.2010 05:20 schrieb Ivan Miljenovic:
>> So I thought it's just an error in the show instance of PortNumber, which
>> shows the bytes flipped. But if I use the following code snippet
>>
>> sock <- socket AF_INET Datagram 0
>> bindSocket sock $ SockAddrInet (PortNum 8888) iNADDR_ANY
>>
>> to bind a socket to port 8888, netstat and TCPView reveal that the socket is
>> actually bound to the wrong port 47138. I'm using network-2.2.1.7 on Windows
>> XP. Is that a bug or am I doing something wrong here?
>
> Tried testing this as well; not sure how to test if the binding worked
> but "netstat --numeric-ports" didn't contain 8888 or 47138.
Hi Ivan,
here's a complete program to reproduce the error:
module Main (main) where
import Network.Socket
main :: IO ()
main = withSocketsDo $ do
sock <- socket AF_INET Datagram 0
bindSocket sock $ SockAddrInet (PortNum 8888) iNADDR_ANY
recvFrom sock 65535
return ()
The output of netstat/TCPView after starting the program is:
MinSocketBind.exe:2724 UDP PC1:47138 *:*
By the way, I'm using GHC 6.10.4, which I think shouldn't make a difference.
Matthias
More information about the Haskell-Cafe
mailing list