Haskell network sample

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Haskell network sample

yang.zhao
hi guys,
I'm newbie, just begin to learn Haskell.
now i write a very simple server and client .

Server:
import Control.Concurrent
import System.IO
import Network

port :: Int
port = 1234

main :: IO ()
main = withSocketsDo $ do
    s <- listenOn $ PortNumber $ fromIntegral port
    (h, _, _) <- accept s

    sline <- hGetLine h
    hPutStrLn h sline
    putStrLn $ "send "++sline
    threadDelay 1000000

    hClose h
    sClose s

Client :
import System.IO
import Network

port :: Int
port = 1234

main :: IO ()
main = withSocketsDo $ do
    h <- connectTo "localhost" $ PortNumber $ fromIntegral port
    hPutStrLn h "hello"
    bs <- hGetContents h
    putStrLn bs
    hClose h


And, it doesn't work now . I run ./serv , then run ./cli , they will block
all the time.
but,  when i run ./serv, and telnet localhost 1234 in another terminal, it
works fine.
so i don't know what's the wrong with my code.
anybody can tell me about my problem?

os is Debian 7,  haskell-platform  2012.2.0.0

thanks a lot!!!
--
K.I.S.S.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140521/8eeb30be/attachment-0001.html>

Reply | Threaded
Open this post in threaded view
|

Haskell network sample

Bob Ippolito
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.

It works for me here on Mac OS X 10.9.2 with GHC 7.8.2.


On Tue, May 20, 2014 at 10:42 PM, yang.zhao <hckjsnzf at gmail.com> wrote:

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

Reply | Threaded
Open this post in threaded view
|

Haskell network sample

yang.zhao
thanks for your replay.
i run the two program in two different teriminal for sure.

it works for you?
but why can't run well on my computer.

make me creazy....


2014-05-21 13:47 GMT+08:00 Bob Ippolito <bob at redivi.com>:

> 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.
>
> It works for me here on Mac OS X 10.9.2 with GHC 7.8.2.
>
>
> On Tue, May 20, 2014 at 10:42 PM, yang.zhao <hckjsnzf at gmail.com> wrote:
>
>> hi guys,
>> I'm newbie, just begin to learn Haskell.
>> now i write a very simple server and client .
>>
>> Server:
>> import Control.Concurrent
>> import System.IO
>> import Network
>>
>> port :: Int
>> port = 1234
>>
>> main :: IO ()
>> main = withSocketsDo $ do
>>     s <- listenOn $ PortNumber $ fromIntegral port
>>     (h, _, _) <- accept s
>>
>>     sline <- hGetLine h
>>     hPutStrLn h sline
>>     putStrLn $ "send "++sline
>>     threadDelay 1000000
>>
>>     hClose h
>>     sClose s
>>
>> Client :
>> import System.IO
>> import Network
>>
>> port :: Int
>> port = 1234
>>
>> main :: IO ()
>> main = withSocketsDo $ do
>>     h <- connectTo "localhost" $ PortNumber $ fromIntegral port
>>     hPutStrLn h "hello"
>>     bs <- hGetContents h
>>     putStrLn bs
>>     hClose h
>>
>>
>> And, it doesn't work now . I run ./serv , then run ./cli , they will
>> block all the time.
>> but,  when i run ./serv, and telnet localhost 1234 in another terminal,
>> it works fine.
>> so i don't know what's the wrong with my code.
>> anybody can tell me about my problem?
>>
>> os is Debian 7,  haskell-platform  2012.2.0.0
>>
>> thanks a lot!!!
>> --
>> K.I.S.S.
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>


--
K.I.S.S.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140521/74f4d77d/attachment.html>

Reply | Threaded
Open this post in threaded view
|

Haskell network sample

Bob Ippolito
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).

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.



On Tue, May 20, 2014 at 10:51 PM, yang.zhao <hckjsnzf at gmail.com> wrote:

> thanks for your replay.
> i run the two program in two different teriminal for sure.
>
> it works for you?
> but why can't run well on my computer.
>
> make me creazy....
>
>
> 2014-05-21 13:47 GMT+08:00 Bob Ippolito <bob at redivi.com>:
>
> 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.
>>
>> It works for me here on Mac OS X 10.9.2 with GHC 7.8.2.
>>
>>
>> On Tue, May 20, 2014 at 10:42 PM, yang.zhao <hckjsnzf at gmail.com> wrote:
>>
>>> hi guys,
>>> I'm newbie, just begin to learn Haskell.
>>> now i write a very simple server and client .
>>>
>>> Server:
>>> import Control.Concurrent
>>> import System.IO
>>> import Network
>>>
>>> port :: Int
>>> port = 1234
>>>
>>> main :: IO ()
>>> main = withSocketsDo $ do
>>>     s <- listenOn $ PortNumber $ fromIntegral port
>>>     (h, _, _) <- accept s
>>>
>>>     sline <- hGetLine h
>>>     hPutStrLn h sline
>>>     putStrLn $ "send "++sline
>>>     threadDelay 1000000
>>>
>>>     hClose h
>>>     sClose s
>>>
>>> Client :
>>> import System.IO
>>> import Network
>>>
>>> port :: Int
>>> port = 1234
>>>
>>> main :: IO ()
>>> main = withSocketsDo $ do
>>>     h <- connectTo "localhost" $ PortNumber $ fromIntegral port
>>>     hPutStrLn h "hello"
>>>     bs <- hGetContents h
>>>     putStrLn bs
>>>     hClose h
>>>
>>>
>>> And, it doesn't work now . I run ./serv , then run ./cli , they will
>>> block all the time.
>>> but,  when i run ./serv, and telnet localhost 1234 in another terminal,
>>> it works fine.
>>> so i don't know what's the wrong with my code.
>>> anybody can tell me about my problem?
>>>
>>> os is Debian 7,  haskell-platform  2012.2.0.0
>>>
>>> thanks a lot!!!
>>> --
>>> K.I.S.S.
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
>
> --
> K.I.S.S.
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140520/ff48e97c/attachment.html>

Reply | Threaded
Open this post in threaded view
|

Haskell network sample

yang.zhao
Here's my new code:

$ cat serv.hs
import Control.Concurrent
import System.IO
import Network

port :: Int
port = 1234

main :: IO ()
main = withSocketsDo $ do
    s <- listenOn $ PortNumber $ fromIntegral port
    putStrLn "Listening..."
    (h, _, _) <- accept s
    putStrLn "After accept"
    sline <- hGetLine h
    putStrLn "get line from handle"
    hPutStrLn h sline
    putStrLn $ "send "++sline
    threadDelay 1000000

    hClose h
    sClose s

--------
$ cat clie.hs
import System.IO
import Network

port :: Int
port = 1234

main :: IO ()
main = withSocketsDo $ do
    h <- connectTo "127.0.0.1" $ PortNumber $ fromIntegral port
    putStrLn "After connect"
    hPutStrLn h "hello"
    putStrLn "put hello to handle done"
    bs <- hGetContents h
    putStrLn "read from handle done"
    putStrLn bs
    hClose h


===
one terminal, run ./serv, then run ./clie in another terminal. Output is :

$ ./serv
Listening...
After accept

$ ./clie
After connect
put hello to handle done
read from handle done


it seems that client has read from then handle, but donesn't read anything,
then block.
and server donesn't receive anything, still wait for something...

ghc version is 7.4.1, because of this?..


2014-05-21 13:57 GMT+08:00 Bob Ippolito <bob at redivi.com>:

> 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).
>
> 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.
>
>
>
> On Tue, May 20, 2014 at 10:51 PM, yang.zhao <hckjsnzf at gmail.com> wrote:
>
>> thanks for your replay.
>> i run the two program in two different teriminal for sure.
>>
>> it works for you?
>> but why can't run well on my computer.
>>
>> make me creazy....
>>
>>
>> 2014-05-21 13:47 GMT+08:00 Bob Ippolito <bob at redivi.com>:
>>
>> 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.
>>>
>>> It works for me here on Mac OS X 10.9.2 with GHC 7.8.2.
>>>
>>>
>>> On Tue, May 20, 2014 at 10:42 PM, yang.zhao <hckjsnzf at gmail.com> wrote:
>>>
>>>> hi guys,
>>>> I'm newbie, just begin to learn Haskell.
>>>> now i write a very simple server and client .
>>>>
>>>> Server:
>>>> import Control.Concurrent
>>>> import System.IO
>>>> import Network
>>>>
>>>> port :: Int
>>>> port = 1234
>>>>
>>>> main :: IO ()
>>>> main = withSocketsDo $ do
>>>>     s <- listenOn $ PortNumber $ fromIntegral port
>>>>     (h, _, _) <- accept s
>>>>
>>>>     sline <- hGetLine h
>>>>     hPutStrLn h sline
>>>>     putStrLn $ "send "++sline
>>>>     threadDelay 1000000
>>>>
>>>>     hClose h
>>>>     sClose s
>>>>
>>>> Client :
>>>> import System.IO
>>>> import Network
>>>>
>>>> port :: Int
>>>> port = 1234
>>>>
>>>> main :: IO ()
>>>> main = withSocketsDo $ do
>>>>     h <- connectTo "localhost" $ PortNumber $ fromIntegral port
>>>>     hPutStrLn h "hello"
>>>>     bs <- hGetContents h
>>>>     putStrLn bs
>>>>     hClose h
>>>>
>>>>
>>>> And, it doesn't work now . I run ./serv , then run ./cli , they will
>>>> block all the time.
>>>> but,  when i run ./serv, and telnet localhost 1234 in another terminal,
>>>> it works fine.
>>>> so i don't know what's the wrong with my code.
>>>> anybody can tell me about my problem?
>>>>
>>>> os is Debian 7,  haskell-platform  2012.2.0.0
>>>>
>>>> thanks a lot!!!
>>>> --
>>>> K.I.S.S.
>>>>
>>>> _______________________________________________
>>>> Beginners mailing list
>>>> Beginners at haskell.org
>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>
>>>>
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>>
>>
>>
>> --
>> K.I.S.S.
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>


--
K.I.S.S.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140521/7498d4b4/attachment-0001.html>

Reply | Threaded
Open this post in threaded view
|

Haskell network sample

Bob Ippolito
I don't have a GHC installation that old, but I think that a bug in that
version of GHC is the only reasonable explanation for this. I highly
recommend that you upgrade to GHC 7.8.x or at least 7.6.x.

Lazy IO is a bit unsafe and error-prone in some scenarios. hGetContents
doesn't really do any reading from the handle until the input is demanded,
which is why you can print "read from handle done" but not the contents of
bs.


On Tue, May 20, 2014 at 11:10 PM, yang.zhao <hckjsnzf at gmail.com> wrote:

> Here's my new code:
>
> $ cat serv.hs
>
> import Control.Concurrent
> import System.IO
> import Network
>
> port :: Int
> port = 1234
>
> main :: IO ()
> main = withSocketsDo $ do
>     s <- listenOn $ PortNumber $ fromIntegral port
>     putStrLn "Listening..."
>
>     (h, _, _) <- accept s
>     putStrLn "After accept"
>     sline <- hGetLine h
>     putStrLn "get line from handle"
>
>     hPutStrLn h sline
>     putStrLn $ "send "++sline
>     threadDelay 1000000
>
>     hClose h
>     sClose s
>
> --------
> $ cat clie.hs
>
> import System.IO
> import Network
>
> port :: Int
> port = 1234
>
> main :: IO ()
> main = withSocketsDo $ do
>     h <- connectTo "127.0.0.1" $ PortNumber $ fromIntegral port
>     putStrLn "After connect"
>     hPutStrLn h "hello"
>     putStrLn "put hello to handle done"
>     bs <- hGetContents h
>     putStrLn "read from handle done"
>     putStrLn bs
>     hClose h
>
>
> ===
> one terminal, run ./serv, then run ./clie in another terminal. Output is :
>
> $ ./serv
> Listening...
> After accept
>
> $ ./clie
> After connect
> put hello to handle done
> read from handle done
>
>
> it seems that client has read from then handle, but donesn't read
> anything, then block.
> and server donesn't receive anything, still wait for something...
>
> ghc version is 7.4.1, because of this?..
>
>
> 2014-05-21 13:57 GMT+08:00 Bob Ippolito <bob at redivi.com>:
>
> 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).
>>
>> 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.
>>
>>
>>
>> On Tue, May 20, 2014 at 10:51 PM, yang.zhao <hckjsnzf at gmail.com> wrote:
>>
>>> thanks for your replay.
>>> i run the two program in two different teriminal for sure.
>>>
>>> it works for you?
>>> but why can't run well on my computer.
>>>
>>> make me creazy....
>>>
>>>
>>> 2014-05-21 13:47 GMT+08:00 Bob Ippolito <bob at redivi.com>:
>>>
>>> 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.
>>>>
>>>> It works for me here on Mac OS X 10.9.2 with GHC 7.8.2.
>>>>
>>>>
>>>> On Tue, May 20, 2014 at 10:42 PM, yang.zhao <hckjsnzf at gmail.com> wrote:
>>>>
>>>>> hi guys,
>>>>> I'm newbie, just begin to learn Haskell.
>>>>> now i write a very simple server and client .
>>>>>
>>>>> Server:
>>>>> import Control.Concurrent
>>>>> import System.IO
>>>>> import Network
>>>>>
>>>>> port :: Int
>>>>> port = 1234
>>>>>
>>>>> main :: IO ()
>>>>> main = withSocketsDo $ do
>>>>>     s <- listenOn $ PortNumber $ fromIntegral port
>>>>>     (h, _, _) <- accept s
>>>>>
>>>>>     sline <- hGetLine h
>>>>>     hPutStrLn h sline
>>>>>     putStrLn $ "send "++sline
>>>>>     threadDelay 1000000
>>>>>
>>>>>     hClose h
>>>>>     sClose s
>>>>>
>>>>> Client :
>>>>> import System.IO
>>>>> import Network
>>>>>
>>>>> port :: Int
>>>>> port = 1234
>>>>>
>>>>> main :: IO ()
>>>>> main = withSocketsDo $ do
>>>>>     h <- connectTo "localhost" $ PortNumber $ fromIntegral port
>>>>>     hPutStrLn h "hello"
>>>>>     bs <- hGetContents h
>>>>>     putStrLn bs
>>>>>     hClose h
>>>>>
>>>>>
>>>>> And, it doesn't work now . I run ./serv , then run ./cli , they will
>>>>> block all the time.
>>>>> but,  when i run ./serv, and telnet localhost 1234 in another
>>>>> terminal, it works fine.
>>>>> so i don't know what's the wrong with my code.
>>>>> anybody can tell me about my problem?
>>>>>
>>>>> os is Debian 7,  haskell-platform  2012.2.0.0
>>>>>
>>>>> thanks a lot!!!
>>>>> --
>>>>> K.I.S.S.
>>>>>
>>>>> _______________________________________________
>>>>> Beginners mailing list
>>>>> Beginners at haskell.org
>>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> Beginners mailing list
>>>> Beginners at haskell.org
>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>
>>>>
>>>
>>>
>>> --
>>> K.I.S.S.
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
>
> --
> K.I.S.S.
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140521/4562af4f/attachment.html>

Reply | Threaded
Open this post in threaded view
|

Haskell network sample

yang.zhao
In reply to this post by yang.zhao
omg, i test it on Windows, it's ok now. GHC is 7.6.3.
i really don't konw why this happen..

but there is another question on Windows

main = withSocketsDo $ do
    s <- listenOn $ PortNumber $ fromIntegral port
    putStrLn "Listening..."
    (h, _, _) <- accept s
    putStrLn "After accept"
    sline <- hGetLine h
    putStrLn $ "get line from handle"++sline
    hPutStrLn h "xxxx...."
    putStrLn "send first done"

    --second recv
    slinea <- hGetLine h
    putStrLn $ "get line from handle"++slinea

    hPutStrLn h "yyyy....."
    putStrLn "send second done"

    threadDelay 1000000
--
cli:
main = withSocketsDo $ do
    h <- connectTo "127.0.0.1" $ PortNumber $ fromIntegral port
    putStrLn "After connect"
    hPutStrLn h "xxx"
    putStrLn "put first to handle done"
    bs <- hGetContents h
    putStrLn "read from handle done "
    putStrLn bs

    --second send
    hPutStrLn h "yyy"
    putStrLn "put second to handle done"
    bfs <- hGetContents h
    putStrLn "read from handle done "
    putStrLn bs


the second send and recv is blocking...
server's output:
Listening...
After accept
get line from handlexxx
send first done

client's output:
After connect
put first to handle done
read from handle done
xxx....


..... T_T




2014-05-21 14:10 GMT+08:00 yang.zhao <hckjsnzf at gmail.com>:

> Here's my new code:
>
> $ cat serv.hs
>
> import Control.Concurrent
> import System.IO
> import Network
>
> port :: Int
> port = 1234
>
> main :: IO ()
> main = withSocketsDo $ do
>     s <- listenOn $ PortNumber $ fromIntegral port
>     putStrLn "Listening..."
>
>     (h, _, _) <- accept s
>     putStrLn "After accept"
>     sline <- hGetLine h
>     putStrLn "get line from handle"
>
>     hPutStrLn h sline
>     putStrLn $ "send "++sline
>     threadDelay 1000000
>
>     hClose h
>     sClose s
>
> --------
> $ cat clie.hs
>
> import System.IO
> import Network
>
> port :: Int
> port = 1234
>
> main :: IO ()
> main = withSocketsDo $ do
>     h <- connectTo "127.0.0.1" $ PortNumber $ fromIntegral port
>     putStrLn "After connect"
>     hPutStrLn h "hello"
>     putStrLn "put hello to handle done"
>     bs <- hGetContents h
>     putStrLn "read from handle done"
>     putStrLn bs
>     hClose h
>
>
> ===
> one terminal, run ./serv, then run ./clie in another terminal. Output is :
>
> $ ./serv
> Listening...
> After accept
>
> $ ./clie
> After connect
> put hello to handle done
> read from handle done
>
>
> it seems that client has read from then handle, but donesn't read
> anything, then block.
> and server donesn't receive anything, still wait for something...
>
> ghc version is 7.4.1, because of this?..
>
>
> 2014-05-21 13:57 GMT+08:00 Bob Ippolito <bob at redivi.com>:
>
> 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).
>>
>> 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.
>>
>>
>>
>> On Tue, May 20, 2014 at 10:51 PM, yang.zhao <hckjsnzf at gmail.com> wrote:
>>
>>> thanks for your replay.
>>> i run the two program in two different teriminal for sure.
>>>
>>> it works for you?
>>> but why can't run well on my computer.
>>>
>>> make me creazy....
>>>
>>>
>>> 2014-05-21 13:47 GMT+08:00 Bob Ippolito <bob at redivi.com>:
>>>
>>> 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.
>>>>
>>>> It works for me here on Mac OS X 10.9.2 with GHC 7.8.2.
>>>>
>>>>
>>>> On Tue, May 20, 2014 at 10:42 PM, yang.zhao <hckjsnzf at gmail.com> wrote:
>>>>
>>>>> hi guys,
>>>>> I'm newbie, just begin to learn Haskell.
>>>>> now i write a very simple server and client .
>>>>>
>>>>> Server:
>>>>> import Control.Concurrent
>>>>> import System.IO
>>>>> import Network
>>>>>
>>>>> port :: Int
>>>>> port = 1234
>>>>>
>>>>> main :: IO ()
>>>>> main = withSocketsDo $ do
>>>>>     s <- listenOn $ PortNumber $ fromIntegral port
>>>>>     (h, _, _) <- accept s
>>>>>
>>>>>     sline <- hGetLine h
>>>>>     hPutStrLn h sline
>>>>>     putStrLn $ "send "++sline
>>>>>     threadDelay 1000000
>>>>>
>>>>>     hClose h
>>>>>     sClose s
>>>>>
>>>>> Client :
>>>>> import System.IO
>>>>> import Network
>>>>>
>>>>> port :: Int
>>>>> port = 1234
>>>>>
>>>>> main :: IO ()
>>>>> main = withSocketsDo $ do
>>>>>     h <- connectTo "localhost" $ PortNumber $ fromIntegral port
>>>>>     hPutStrLn h "hello"
>>>>>     bs <- hGetContents h
>>>>>     putStrLn bs
>>>>>     hClose h
>>>>>
>>>>>
>>>>> And, it doesn't work now . I run ./serv , then run ./cli , they will
>>>>> block all the time.
>>>>> but,  when i run ./serv, and telnet localhost 1234 in another
>>>>> terminal, it works fine.
>>>>> so i don't know what's the wrong with my code.
>>>>> anybody can tell me about my problem?
>>>>>
>>>>> os is Debian 7,  haskell-platform  2012.2.0.0
>>>>>
>>>>> thanks a lot!!!
>>>>> --
>>>>> K.I.S.S.
>>>>>
>>>>> _______________________________________________
>>>>> Beginners mailing list
>>>>> Beginners at haskell.org
>>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> Beginners mailing list
>>>> Beginners at haskell.org
>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>
>>>>
>>>
>>>
>>> --
>>> K.I.S.S.
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
>
> --
> K.I.S.S.
>



--
K.I.S.S.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140521/f86e1458/attachment-0001.html>

Reply | Threaded
Open this post in threaded view
|

Haskell network sample

Bob Ippolito
hGetContents reads a handle until EOF, so you've implement a deadlock. The
server is waiting to read a second line, but the client is waiting for the
server to close the socket in order to do the first print. Perhaps you
meant to use hGetLine instead?



On Wed, May 21, 2014 at 12:15 AM, yang.zhao <hckjsnzf at gmail.com> wrote:

> omg, i test it on Windows, it's ok now. GHC is 7.6.3.
> i really don't konw why this happen..
>
> but there is another question on Windows
>
>
> main = withSocketsDo $ do
>     s <- listenOn $ PortNumber $ fromIntegral port
>     putStrLn "Listening..."
>     (h, _, _) <- accept s
>     putStrLn "After accept"
>     sline <- hGetLine h
>     putStrLn $ "get line from handle"++sline
>     hPutStrLn h "xxxx...."
>     putStrLn "send first done"
>
>     --second recv
>     slinea <- hGetLine h
>     putStrLn $ "get line from handle"++slinea
>
>     hPutStrLn h "yyyy....."
>     putStrLn "send second done"
>
>     threadDelay 1000000
> --
> cli:
>
> main = withSocketsDo $ do
>     h <- connectTo "127.0.0.1" $ PortNumber $ fromIntegral port
>     putStrLn "After connect"
>     hPutStrLn h "xxx"
>     putStrLn "put first to handle done"
>
>     bs <- hGetContents h
>     putStrLn "read from handle done "
>     putStrLn bs
>
>     --second send
>     hPutStrLn h "yyy"
>     putStrLn "put second to handle done"
>     bfs <- hGetContents h
>
>     putStrLn "read from handle done "
>     putStrLn bs
>
>
> the second send and recv is blocking...
> server's output:
> Listening...
> After accept
> get line from handlexxx
> send first done
>
> client's output:
> After connect
> put first to handle done
> read from handle done
> xxx....
>
>
> ..... T_T
>
>
>
>
> 2014-05-21 14:10 GMT+08:00 yang.zhao <hckjsnzf at gmail.com>:
>
> Here's my new code:
>>
>> $ cat serv.hs
>>
>> import Control.Concurrent
>> import System.IO
>> import Network
>>
>> port :: Int
>> port = 1234
>>
>> main :: IO ()
>> main = withSocketsDo $ do
>>     s <- listenOn $ PortNumber $ fromIntegral port
>>     putStrLn "Listening..."
>>
>>     (h, _, _) <- accept s
>>     putStrLn "After accept"
>>     sline <- hGetLine h
>>     putStrLn "get line from handle"
>>
>>     hPutStrLn h sline
>>     putStrLn $ "send "++sline
>>     threadDelay 1000000
>>
>>     hClose h
>>     sClose s
>>
>> --------
>> $ cat clie.hs
>>
>> import System.IO
>> import Network
>>
>> port :: Int
>> port = 1234
>>
>> main :: IO ()
>> main = withSocketsDo $ do
>>     h <- connectTo "127.0.0.1" $ PortNumber $ fromIntegral port
>>     putStrLn "After connect"
>>     hPutStrLn h "hello"
>>     putStrLn "put hello to handle done"
>>     bs <- hGetContents h
>>     putStrLn "read from handle done"
>>     putStrLn bs
>>     hClose h
>>
>>
>> ===
>> one terminal, run ./serv, then run ./clie in another terminal. Output is :
>>
>> $ ./serv
>> Listening...
>> After accept
>>
>> $ ./clie
>> After connect
>> put hello to handle done
>> read from handle done
>>
>>
>> it seems that client has read from then handle, but donesn't read
>> anything, then block.
>> and server donesn't receive anything, still wait for something...
>>
>> ghc version is 7.4.1, because of this?..
>>
>>
>> 2014-05-21 13:57 GMT+08:00 Bob Ippolito <bob at redivi.com>:
>>
>> 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).
>>>
>>> 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.
>>>
>>>
>>>
>>> On Tue, May 20, 2014 at 10:51 PM, yang.zhao <hckjsnzf at gmail.com> wrote:
>>>
>>>> thanks for your replay.
>>>> i run the two program in two different teriminal for sure.
>>>>
>>>> it works for you?
>>>> but why can't run well on my computer.
>>>>
>>>> make me creazy....
>>>>
>>>>
>>>> 2014-05-21 13:47 GMT+08:00 Bob Ippolito <bob at redivi.com>:
>>>>
>>>> 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.
>>>>>
>>>>> It works for me here on Mac OS X 10.9.2 with GHC 7.8.2.
>>>>>
>>>>>
>>>>> On Tue, May 20, 2014 at 10:42 PM, yang.zhao <hckjsnzf at gmail.com>wrote:
>>>>>
>>>>>> hi guys,
>>>>>> I'm newbie, just begin to learn Haskell.
>>>>>> now i write a very simple server and client .
>>>>>>
>>>>>> Server:
>>>>>> import Control.Concurrent
>>>>>> import System.IO
>>>>>> import Network
>>>>>>
>>>>>> port :: Int
>>>>>> port = 1234
>>>>>>
>>>>>> main :: IO ()
>>>>>> main = withSocketsDo $ do
>>>>>>     s <- listenOn $ PortNumber $ fromIntegral port
>>>>>>     (h, _, _) <- accept s
>>>>>>
>>>>>>     sline <- hGetLine h
>>>>>>     hPutStrLn h sline
>>>>>>     putStrLn $ "send "++sline
>>>>>>     threadDelay 1000000
>>>>>>
>>>>>>     hClose h
>>>>>>     sClose s
>>>>>>
>>>>>> Client :
>>>>>> import System.IO
>>>>>> import Network
>>>>>>
>>>>>> port :: Int
>>>>>> port = 1234
>>>>>>
>>>>>> main :: IO ()
>>>>>> main = withSocketsDo $ do
>>>>>>     h <- connectTo "localhost" $ PortNumber $ fromIntegral port
>>>>>>     hPutStrLn h "hello"
>>>>>>     bs <- hGetContents h
>>>>>>     putStrLn bs
>>>>>>     hClose h
>>>>>>
>>>>>>
>>>>>> And, it doesn't work now . I run ./serv , then run ./cli , they will
>>>>>> block all the time.
>>>>>> but,  when i run ./serv, and telnet localhost 1234 in another
>>>>>> terminal, it works fine.
>>>>>> so i don't know what's the wrong with my code.
>>>>>> anybody can tell me about my problem?
>>>>>>
>>>>>> os is Debian 7,  haskell-platform  2012.2.0.0
>>>>>>
>>>>>> thanks a lot!!!
>>>>>> --
>>>>>> K.I.S.S.
>>>>>>
>>>>>> _______________________________________________
>>>>>> Beginners mailing list
>>>>>> Beginners at haskell.org
>>>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>>>
>>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Beginners mailing list
>>>>> Beginners at haskell.org
>>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> K.I.S.S.
>>>>
>>>> _______________________________________________
>>>> Beginners mailing list
>>>> Beginners at haskell.org
>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>
>>>>
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>>
>>
>>
>> --
>> K.I.S.S.
>>
>
>
>
> --
> K.I.S.S.
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140521/cdfb3161/attachment.html>

Reply | Threaded
Open this post in threaded view
|

Haskell network sample

Sylvain HENRY
In reply to this post by yang.zhao
hGetContents puts the handle in semi-closed state and reads until there is
nothing left to read. Hence you have a deadlock. Use hGetLine in "cli".

Sylvain


2014-05-21 9:15 GMT+02:00 yang.zhao <hckjsnzf at gmail.com>:

> omg, i test it on Windows, it's ok now. GHC is 7.6.3.
> i really don't konw why this happen..
>
> but there is another question on Windows
>
>
> main = withSocketsDo $ do
>     s <- listenOn $ PortNumber $ fromIntegral port
>     putStrLn "Listening..."
>     (h, _, _) <- accept s
>     putStrLn "After accept"
>     sline <- hGetLine h
>     putStrLn $ "get line from handle"++sline
>     hPutStrLn h "xxxx...."
>     putStrLn "send first done"
>
>     --second recv
>     slinea <- hGetLine h
>     putStrLn $ "get line from handle"++slinea
>
>     hPutStrLn h "yyyy....."
>     putStrLn "send second done"
>
>     threadDelay 1000000
> --
> cli:
>
> main = withSocketsDo $ do
>     h <- connectTo "127.0.0.1" $ PortNumber $ fromIntegral port
>     putStrLn "After connect"
>     hPutStrLn h "xxx"
>     putStrLn "put first to handle done"
>
>     bs <- hGetContents h
>     putStrLn "read from handle done "
>     putStrLn bs
>
>     --second send
>     hPutStrLn h "yyy"
>     putStrLn "put second to handle done"
>     bfs <- hGetContents h
>
>     putStrLn "read from handle done "
>     putStrLn bs
>
>
> the second send and recv is blocking...
> server's output:
> Listening...
> After accept
> get line from handlexxx
> send first done
>
> client's output:
> After connect
> put first to handle done
> read from handle done
> xxx....
>
>
> ..... T_T
>
>
>
>
> 2014-05-21 14:10 GMT+08:00 yang.zhao <hckjsnzf at gmail.com>:
>
> Here's my new code:
>>
>> $ cat serv.hs
>>
>> import Control.Concurrent
>> import System.IO
>> import Network
>>
>> port :: Int
>> port = 1234
>>
>> main :: IO ()
>> main = withSocketsDo $ do
>>     s <- listenOn $ PortNumber $ fromIntegral port
>>     putStrLn "Listening..."
>>
>>     (h, _, _) <- accept s
>>     putStrLn "After accept"
>>     sline <- hGetLine h
>>     putStrLn "get line from handle"
>>
>>     hPutStrLn h sline
>>     putStrLn $ "send "++sline
>>     threadDelay 1000000
>>
>>     hClose h
>>     sClose s
>>
>> --------
>> $ cat clie.hs
>>
>> import System.IO
>> import Network
>>
>> port :: Int
>> port = 1234
>>
>> main :: IO ()
>> main = withSocketsDo $ do
>>     h <- connectTo "127.0.0.1" $ PortNumber $ fromIntegral port
>>     putStrLn "After connect"
>>     hPutStrLn h "hello"
>>     putStrLn "put hello to handle done"
>>     bs <- hGetContents h
>>     putStrLn "read from handle done"
>>     putStrLn bs
>>     hClose h
>>
>>
>> ===
>> one terminal, run ./serv, then run ./clie in another terminal. Output is :
>>
>> $ ./serv
>> Listening...
>> After accept
>>
>> $ ./clie
>> After connect
>> put hello to handle done
>> read from handle done
>>
>>
>> it seems that client has read from then handle, but donesn't read
>> anything, then block.
>> and server donesn't receive anything, still wait for something...
>>
>> ghc version is 7.4.1, because of this?..
>>
>>
>> 2014-05-21 13:57 GMT+08:00 Bob Ippolito <bob at redivi.com>:
>>
>> 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).
>>>
>>> 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.
>>>
>>>
>>>
>>> On Tue, May 20, 2014 at 10:51 PM, yang.zhao <hckjsnzf at gmail.com> wrote:
>>>
>>>> thanks for your replay.
>>>> i run the two program in two different teriminal for sure.
>>>>
>>>> it works for you?
>>>> but why can't run well on my computer.
>>>>
>>>> make me creazy....
>>>>
>>>>
>>>> 2014-05-21 13:47 GMT+08:00 Bob Ippolito <bob at redivi.com>:
>>>>
>>>> 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.
>>>>>
>>>>> It works for me here on Mac OS X 10.9.2 with GHC 7.8.2.
>>>>>
>>>>>
>>>>> On Tue, May 20, 2014 at 10:42 PM, yang.zhao <hckjsnzf at gmail.com>wrote:
>>>>>
>>>>>> hi guys,
>>>>>> I'm newbie, just begin to learn Haskell.
>>>>>> now i write a very simple server and client .
>>>>>>
>>>>>> Server:
>>>>>> import Control.Concurrent
>>>>>> import System.IO
>>>>>> import Network
>>>>>>
>>>>>> port :: Int
>>>>>> port = 1234
>>>>>>
>>>>>> main :: IO ()
>>>>>> main = withSocketsDo $ do
>>>>>>     s <- listenOn $ PortNumber $ fromIntegral port
>>>>>>     (h, _, _) <- accept s
>>>>>>
>>>>>>     sline <- hGetLine h
>>>>>>     hPutStrLn h sline
>>>>>>     putStrLn $ "send "++sline
>>>>>>     threadDelay 1000000
>>>>>>
>>>>>>     hClose h
>>>>>>     sClose s
>>>>>>
>>>>>> Client :
>>>>>> import System.IO
>>>>>> import Network
>>>>>>
>>>>>> port :: Int
>>>>>> port = 1234
>>>>>>
>>>>>> main :: IO ()
>>>>>> main = withSocketsDo $ do
>>>>>>     h <- connectTo "localhost" $ PortNumber $ fromIntegral port
>>>>>>     hPutStrLn h "hello"
>>>>>>     bs <- hGetContents h
>>>>>>     putStrLn bs
>>>>>>     hClose h
>>>>>>
>>>>>>
>>>>>> And, it doesn't work now . I run ./serv , then run ./cli , they will
>>>>>> block all the time.
>>>>>> but,  when i run ./serv, and telnet localhost 1234 in another
>>>>>> terminal, it works fine.
>>>>>> so i don't know what's the wrong with my code.
>>>>>> anybody can tell me about my problem?
>>>>>>
>>>>>> os is Debian 7,  haskell-platform  2012.2.0.0
>>>>>>
>>>>>> thanks a lot!!!
>>>>>> --
>>>>>> K.I.S.S.
>>>>>>
>>>>>> _______________________________________________
>>>>>> Beginners mailing list
>>>>>> Beginners at haskell.org
>>>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>>>
>>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Beginners mailing list
>>>>> Beginners at haskell.org
>>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> K.I.S.S.
>>>>
>>>> _______________________________________________
>>>> Beginners mailing list
>>>> Beginners at haskell.org
>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>
>>>>
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>>
>>
>>
>> --
>> K.I.S.S.
>>
>
>
>
> --
> K.I.S.S.
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140521/fe56f2c9/attachment-0001.html>

Reply | Threaded
Open this post in threaded view
|

Haskell network sample

yang.zhao
Thank you very much, Bob and Sylvain.
i test hGetLine instead of hGetContents.


2014-05-21 16:07 GMT+08:00 Sylvain Henry <hsyl20 at gmail.com>:

> hGetContents puts the handle in semi-closed state and reads until there is
> nothing left to read. Hence you have a deadlock. Use hGetLine in "cli".
>
> Sylvain
>
>
> 2014-05-21 9:15 GMT+02:00 yang.zhao <hckjsnzf at gmail.com>:
>
> omg, i test it on Windows, it's ok now. GHC is 7.6.3.
>> i really don't konw why this happen..
>>
>> but there is another question on Windows
>>
>>
>> main = withSocketsDo $ do
>>     s <- listenOn $ PortNumber $ fromIntegral port
>>     putStrLn "Listening..."
>>     (h, _, _) <- accept s
>>     putStrLn "After accept"
>>     sline <- hGetLine h
>>     putStrLn $ "get line from handle"++sline
>>     hPutStrLn h "xxxx...."
>>     putStrLn "send first done"
>>
>>     --second recv
>>     slinea <- hGetLine h
>>     putStrLn $ "get line from handle"++slinea
>>
>>     hPutStrLn h "yyyy....."
>>     putStrLn "send second done"
>>
>>     threadDelay 1000000
>> --
>> cli:
>>
>> main = withSocketsDo $ do
>>     h <- connectTo "127.0.0.1" $ PortNumber $ fromIntegral port
>>     putStrLn "After connect"
>>     hPutStrLn h "xxx"
>>     putStrLn "put first to handle done"
>>
>>     bs <- hGetContents h
>>     putStrLn "read from handle done "
>>     putStrLn bs
>>
>>     --second send
>>     hPutStrLn h "yyy"
>>     putStrLn "put second to handle done"
>>     bfs <- hGetContents h
>>
>>     putStrLn "read from handle done "
>>     putStrLn bs
>>
>>
>> the second send and recv is blocking...
>> server's output:
>> Listening...
>> After accept
>> get line from handlexxx
>> send first done
>>
>> client's output:
>> After connect
>> put first to handle done
>> read from handle done
>> xxx....
>>
>>
>> ..... T_T
>>
>>
>>
>>
>> 2014-05-21 14:10 GMT+08:00 yang.zhao <hckjsnzf at gmail.com>:
>>
>> Here's my new code:
>>>
>>> $ cat serv.hs
>>>
>>> import Control.Concurrent
>>> import System.IO
>>> import Network
>>>
>>> port :: Int
>>> port = 1234
>>>
>>> main :: IO ()
>>> main = withSocketsDo $ do
>>>     s <- listenOn $ PortNumber $ fromIntegral port
>>>     putStrLn "Listening..."
>>>
>>>     (h, _, _) <- accept s
>>>     putStrLn "After accept"
>>>     sline <- hGetLine h
>>>     putStrLn "get line from handle"
>>>
>>>     hPutStrLn h sline
>>>     putStrLn $ "send "++sline
>>>     threadDelay 1000000
>>>
>>>     hClose h
>>>     sClose s
>>>
>>> --------
>>> $ cat clie.hs
>>>
>>> import System.IO
>>> import Network
>>>
>>> port :: Int
>>> port = 1234
>>>
>>> main :: IO ()
>>> main = withSocketsDo $ do
>>>     h <- connectTo "127.0.0.1" $ PortNumber $ fromIntegral port
>>>     putStrLn "After connect"
>>>     hPutStrLn h "hello"
>>>     putStrLn "put hello to handle done"
>>>     bs <- hGetContents h
>>>     putStrLn "read from handle done"
>>>     putStrLn bs
>>>     hClose h
>>>
>>>
>>> ===
>>> one terminal, run ./serv, then run ./clie in another terminal. Output is
>>> :
>>>
>>> $ ./serv
>>> Listening...
>>> After accept
>>>
>>> $ ./clie
>>> After connect
>>> put hello to handle done
>>> read from handle done
>>>
>>>
>>> it seems that client has read from then handle, but donesn't read
>>> anything, then block.
>>> and server donesn't receive anything, still wait for something...
>>>
>>> ghc version is 7.4.1, because of this?..
>>>
>>>
>>> 2014-05-21 13:57 GMT+08:00 Bob Ippolito <bob at redivi.com>:
>>>
>>> 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).
>>>>
>>>> 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.
>>>>
>>>>
>>>>
>>>> On Tue, May 20, 2014 at 10:51 PM, yang.zhao <hckjsnzf at gmail.com> wrote:
>>>>
>>>>> thanks for your replay.
>>>>> i run the two program in two different teriminal for sure.
>>>>>
>>>>> it works for you?
>>>>> but why can't run well on my computer.
>>>>>
>>>>> make me creazy....
>>>>>
>>>>>
>>>>> 2014-05-21 13:47 GMT+08:00 Bob Ippolito <bob at redivi.com>:
>>>>>
>>>>> 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.
>>>>>>
>>>>>> It works for me here on Mac OS X 10.9.2 with GHC 7.8.2.
>>>>>>
>>>>>>
>>>>>> On Tue, May 20, 2014 at 10:42 PM, yang.zhao <hckjsnzf at gmail.com>wrote:
>>>>>>
>>>>>>> hi guys,
>>>>>>> I'm newbie, just begin to learn Haskell.
>>>>>>> now i write a very simple server and client .
>>>>>>>
>>>>>>> Server:
>>>>>>> import Control.Concurrent
>>>>>>> import System.IO
>>>>>>> import Network
>>>>>>>
>>>>>>> port :: Int
>>>>>>> port = 1234
>>>>>>>
>>>>>>> main :: IO ()
>>>>>>> main = withSocketsDo $ do
>>>>>>>     s <- listenOn $ PortNumber $ fromIntegral port
>>>>>>>     (h, _, _) <- accept s
>>>>>>>
>>>>>>>     sline <- hGetLine h
>>>>>>>     hPutStrLn h sline
>>>>>>>     putStrLn $ "send "++sline
>>>>>>>     threadDelay 1000000
>>>>>>>
>>>>>>>     hClose h
>>>>>>>     sClose s
>>>>>>>
>>>>>>> Client :
>>>>>>> import System.IO
>>>>>>> import Network
>>>>>>>
>>>>>>> port :: Int
>>>>>>> port = 1234
>>>>>>>
>>>>>>> main :: IO ()
>>>>>>> main = withSocketsDo $ do
>>>>>>>     h <- connectTo "localhost" $ PortNumber $ fromIntegral port
>>>>>>>     hPutStrLn h "hello"
>>>>>>>     bs <- hGetContents h
>>>>>>>     putStrLn bs
>>>>>>>     hClose h
>>>>>>>
>>>>>>>
>>>>>>> And, it doesn't work now . I run ./serv , then run ./cli , they will
>>>>>>> block all the time.
>>>>>>> but,  when i run ./serv, and telnet localhost 1234 in another
>>>>>>> terminal, it works fine.
>>>>>>> so i don't know what's the wrong with my code.
>>>>>>> anybody can tell me about my problem?
>>>>>>>
>>>>>>> os is Debian 7,  haskell-platform  2012.2.0.0
>>>>>>>
>>>>>>> thanks a lot!!!
>>>>>>> --
>>>>>>> K.I.S.S.
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> Beginners mailing list
>>>>>>> Beginners at haskell.org
>>>>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> Beginners mailing list
>>>>>> Beginners at haskell.org
>>>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> K.I.S.S.
>>>>>
>>>>> _______________________________________________
>>>>> Beginners mailing list
>>>>> Beginners at haskell.org
>>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> Beginners mailing list
>>>> Beginners at haskell.org
>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>
>>>>
>>>
>>>
>>> --
>>> K.I.S.S.
>>>
>>
>>
>>
>> --
>> K.I.S.S.
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>


--
K.I.S.S.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140521/7fbdf46d/attachment.html>