I asked a question about signal on windows with the same code,here is another question
import IO
import Control.Exception hiding (catch)
import Control.Concurrent
import Network
main = withSocketsDo $ do {main'}
main' = listenOn (PortNumber 9900) >>= acceptConnections
acceptConnections sock = do
putStrLn $ "trying to accept" ++ (show sock)-- debug msg
conn@(h,host,port) <- accept sock
print conn -- debug msg
forkIO $ catch (talk conn `finally` hClose h) (\e -> print e)
acceptConnections sock
talk conn@(h,_,_) = hGetLine h >>= hPutStrLn h >> hFlush h >> talk conn
I run the program on win7,and it looks like the socket created succeed,but I can’t telnet on,and netstat doesn’t show any listening socket with the process,is there anything wrong?Or,haskell has bug on windows?(By the way,on debian with this code works perfect)
when I use netstat -a on win7,I found the listening ip with port 9900 is [::],neither is 127.0.0.1 nor 0.0.0.0,so I guess the problem is during create socket in function “listenOn”,then I wrote “listenOn2” replaced.And the problem is solved.
Here is the full code:(the only difference is change the proto from [[getProtocolNumber “tcp”]] to [[defaultProtocol]]),maybe this is a bug.