Exception: bind: resource busy (Address already in use)

Hi, I'm trying to work on following code below (code is a copy from herehttp://cogsandlevers.blogspot.no/2013/05/a-tcp-server-haskell-example.html). Problem is that when I close the server with ctrl+c and try to run it again I get: *** Exception: bind: resource busy (Address already in use). In documentation of listenOn is written: NOTE: To avoid the "Address already in use" problems popped up several times on the GHC-Users mailing list we set the ReuseAddrhttp://hackage.haskell.org/packages/archive/network/2.3.0.14/doc/html/Networ...socket option on the listening socket. If you don't want this behaviour, please use the lower level listenhttp://hackage.haskell.org/packages/archive/network/2.3.0.14/doc/html/Networ... instead. Please how can I fix this? (ghci version 7.6.3) cheers m. import Network (listenOn, accept, PortID(..), Socket) import System.IO (hSetBuffering, hGetLine, hPutStrLn, BufferMode(..), Handle) import Control.Concurrent (forkIO) echoImpl :: Handle -> IO () echoImpl client = do line <- hGetLine client hPutStrLn client line echoImpl client clientHandler :: Socket -> IO () clientHandler sock = do (client, _, _) <- accept sock hSetBuffering client NoBuffering forkIO $ echoImpl client clientHandler sock felix :: IO () felix = do sock <- listenOn $ PortNumber 5002 putStrLn $ "Echo server started .." clientHandler sock
participants (1)
-
Miro Karpis