Reading/Writing sockets concurrently

Mårten Dolk dolk at
Fri Dec 10 05:54:46 EST 2004


Thanks for the reply!

ajb at wrote:

>>I'm trying to create a client application that needs to read and write
>>data from a socket. What I want to do is to have one thread reading the
>>socket and another thread writing to the same socket, but I can't get it
>>to work.
>You could take a look at lambdabot:
>It has a two-thread structure similar to what you appear to need.  Look
>in IRC.hs specifically.
That code looked very much like what I was trying to do. The difference? 
I had my writer loop running in the main thread. Forking the writer to 
its own thread did take care of the evil "Fail: thread blocked 
indefinitely". But I'm still not sure about the scheduling/blocking 
issue. You do seem to have one thread reading to the same handle as 
another thread is reading. Isn't that a problem?

Well, the code works well enough for my purposes now. :)

Btw, you import GHC.IO and not System.IO. What is the diffrence between 
those two?


More information about the Glasgow-haskell-users mailing list