[Haskell-beginners] Haskell network sample

yang.zhao hckjsnzf at gmail.com
Wed May 21 05:51:41 UTC 2014


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>


More information about the Beginners mailing list