<div dir="ltr">hi guys,<br>I'm newbie, just begin to learn Haskell.<br>now i write a very simple server and client .<br><br>Server:<br>import Control.Concurrent <br>import System.IO <br>import Network <br>
<br>port :: Int <br>port = 1234 <br> <br>main :: IO () <br>main = withSocketsDo $ do <br> s <- listenOn $ PortNumber $ fromIntegral port<br>
(h, _, _) <- accept s <br> <br> sline <- hGetLine h <br> hPutStrLn h sline <br> putStrLn $ "send "++sline<br> threadDelay 1000000 <br> <br>
hClose h <br> sClose s <br><br>Client :<br>import System.IO<br>import Network<br> <br>port :: Int<br>port = 1234<br> <br>main :: IO ()<br>main = withSocketsDo $ do<br> h <- connectTo "localhost" $ PortNumber $ fromIntegral port<br>
hPutStrLn h "hello"<br> bs <- hGetContents h<br> putStrLn bs<br> hClose h<br> <br clear="all"><br>And, it doesn't work now . I run ./serv , then run ./cli , they will block all the time. <br>
but, when i run ./serv, and telnet localhost 1234 in another terminal, it works fine.<br>so i don't know what's the wrong with my code.<br>anybody can tell me about my problem?<br><br>os is Debian 7, haskell-platform 2012.2.0.0<br>
<br>thanks a lot!!!<br>-- <br>K.I.S.S.
</div>