[Haskell-cafe] Working with Network

Marco Righele marco_righele at yahoo.it
Sun May 23 02:12:38 EDT 2004


Hello everybody.

I'm trying to learn to use Sockets with Haskell, so I started playing 
with a small app that waits for a client and start an interactive 
session, i.e. waits for some input, answers to it, wait for some more etc.

Ideally each session would work more or less as follows:

do    (hdl,hn,pn) <- accept socket
      text <- hGetContents hdl
      inputs <- parse text
      replies <- sequence $ map reply inputs
      sequence $ map (hPrint hdl) replies
      ...

Where parse and reply are IO functions that produce and consume some 
kind of higher level representation of the text that the client sent.
Of course this won't work because the code will first try to read all 
the input and then to write back all the replies. I think that if I had 
two different handles for input and output I wouldn't have this problem, 
am I right ? Is there a way to handle such situation without having to 
read the input text in chunks ? This for example would allow me to use a 
library like Parsec to parse the input (that looks like works on string 
and not on handles)

Thanks,
Marco



More information about the Haskell-Cafe mailing list