<div dir="ltr">Here's my new code:<br><br>$ cat serv.hs<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>
    putStrLn "Listening..."<br>    (h, _, _) <- accept s<br>    putStrLn "After accept"<br>    sline <- hGetLine h<br>    putStrLn "get line from handle"<br>    hPutStrLn h sline<br>    putStrLn $ "send "++sline<br>
    threadDelay 1000000<br><br>    hClose h<br>    sClose s<br><br>--------<br>$ cat clie.hs<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 "127.0.0.1" $ PortNumber $ fromIntegral port<br>
    putStrLn "After connect"<br>    hPutStrLn h "hello"<br>    putStrLn "put hello to handle done"<br>    bs <- hGetContents h<br>    putStrLn "read from handle done"<br>    putStrLn bs<br>
    hClose h<br><br><br>===<br>one terminal, run ./serv, then run ./clie in another terminal. Output is :<br><br>$ ./serv <br>Listening...<br>After accept<br><br>$ ./clie <br>After connect<br>put hello to handle done<br>read from handle done<br>
<br><br>it seems that client has read from then handle, but donesn't read anything, then block.<br>and server donesn't receive anything, still wait for something...<br><br>ghc version is 7.4.1, because of this?..<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-05-21 13:57 GMT+08:00 Bob Ippolito <span dir="ltr"><<a href="mailto:bob@redivi.com" target="_blank">bob@redivi.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Not sure why you're having issues, I just tried it on GHC 7.6.3 on Fedora 20 and it worked fine there as well (both with runhaskell or compiled with -O).<div><br></div><div>I might start adding putStrLn statements to the code to see where it's unexpectedly blocking, or perhaps use 127.0.0.1 instead of "localhost" in case the issue is a DNS misconfiguration.</div>

<div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, May 20, 2014 at 10:51 PM, yang.zhao <span dir="ltr"><<a href="mailto:hckjsnzf@gmail.com" target="_blank">hckjsnzf@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">thanks for your replay.<br>i run the two program in two different teriminal for sure.<br><br>it works for you?<br>

but why can't run well on my computer.<br><br>make me creazy....<br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">2014-05-21 13:47 GMT+08:00 Bob Ippolito <span dir="ltr"><<a href="mailto:bob@redivi.com" target="_blank">bob@redivi.com</a>></span>:<div><div><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div dir="ltr">How precisely are you trying to run the client? Are you typing it in to the same terminal? If so, then the client is never actually started, because when you type ./cli the input is going to ./serv and not the shell. Try running the client in a separate terminal.<div>



<br></div><div>It works for me here on Mac OS X 10.9.2 with GHC 7.8.2.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On Tue, May 20, 2014 at 10:42 PM, yang.zhao <span dir="ltr"><<a href="mailto:hckjsnzf@gmail.com" target="_blank">hckjsnzf@gmail.com</a>></span> wrote:<br>



</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><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!!!<span><font color="#888888"><br>-- <br>K.I.S.S.
</font></span></div>
<br></div></div>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div></div></div><span><font color="#888888"><br><br clear="all"><br>-- <br>K.I.S.S.
</font></span></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>K.I.S.S.
</div>