A question about network programming
 
            Hey all! This is probably a question that shows my incompetence more than anything else, but I'm stuck with some TCP programming. I have some code that looks like this: hdl <- open TCP connection message <- hGetContents hdl answer <- do stuff with message hPut hdl answer hClose hdl My problem is that the stuff that gets done with message happens, but only after I close the connection rom the client's side and then of course it is too late to get the answer out of said connection. What am I doing wrong? Many Thanks Raf
 
            Raphael Päbst 
This is probably a question that shows my incompetence more than anything else, but I'm stuck with some TCP programming.
I have some code that looks like this:
hdl <- open TCP connection message <- hGetContents hdl answer <- do stuff with message hPut hdl answer hClose hdl
My problem is that the stuff that gets done with message happens, but only after I close the connection rom the client's side and then of course it is too late to get the answer out of said connection.
What am I doing wrong?
You are using lazy I/O, which is in general unpredictable. You have almost no control over when the handle is closed. If you want predictable yet elegant I/O, I recommend an iteratee-based approach. There is a nice online tutorial in the Yesod book [1]. [1] http://www.yesodweb.com/book/enumerator BTW, I like your "hab dich lieb" handle. =P Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/
 
            Raphael Päbst 
answer <- do stuff with message
As a side note, if you want to keep your lazy I/O approach, you should make sure that "do stuff with message" does not force the entire list. Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/
 
            I will look into that. My main problem is not the fact that stuff gets
done after I close the handle on the client side, but that I need the
answer on the clientside. Is there any way to achieve this?
On 6/8/11, Ertugrul Soeylemez 
Raphael Päbst
wrote: answer <- do stuff with message
As a side note, if you want to keep your lazy I/O approach, you should make sure that "do stuff with message" does not force the entire list.
Greets, Ertugrul
-- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
 
            Hi Raf,
I found that following the template for servers in the Network
Programming chapter [1] of Real World Haskell is the best way to go.
Scroll down to the "TCP Syslog Server" section for the relevant
information.
-deech
[1] http://book.realworldhaskell.org/read/sockets-and-syslog.html
On Wed, Jun 8, 2011 at 6:29 AM, Raphael Päbst
Hey all! This is probably a question that shows my incompetence more than anything else, but I'm stuck with some TCP programming.
I have some code that looks like this:
hdl <- open TCP connection message <- hGetContents hdl answer <- do stuff with message hPut hdl answer hClose hdl
My problem is that the stuff that gets done with message happens, but only after I close the connection rom the client's side and then of course it is too late to get the answer out of said connection.
What am I doing wrong?
Many Thanks
Raf
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
 
            Hey, that's what I did, pretty much.
I had to inflict some changes on the server though.
I'll play around with it some more and see what happens.
Raf
On 6/8/11, aditya siram 
Hi Raf, I found that following the template for servers in the Network Programming chapter [1] of Real World Haskell is the best way to go. Scroll down to the "TCP Syslog Server" section for the relevant information. -deech
[1] http://book.realworldhaskell.org/read/sockets-and-syslog.html
On Wed, Jun 8, 2011 at 6:29 AM, Raphael Päbst
wrote: Hey all! This is probably a question that shows my incompetence more than anything else, but I'm stuck with some TCP programming.
I have some code that looks like this:
hdl <- open TCP connection message <- hGetContents hdl answer <- do stuff with message hPut hdl answer hClose hdl
My problem is that the stuff that gets done with message happens, but only after I close the connection rom the client's side and then of course it is too late to get the answer out of said connection.
What am I doing wrong?
Many Thanks
Raf
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
 
            Note they set the buffering to line buffered. This way you get data in line based chunks instead of all at once.
You could replace the sock IO with strip and see the difference interactively.
On Jun 8, 2011, at 6:17, Raphael Päbst 
Hey, that's what I did, pretty much. I had to inflict some changes on the server though.
I'll play around with it some more and see what happens.
Raf
On 6/8/11, aditya siram
wrote: Hi Raf, I found that following the template for servers in the Network Programming chapter [1] of Real World Haskell is the best way to go. Scroll down to the "TCP Syslog Server" section for the relevant information. -deech
[1] http://book.realworldhaskell.org/read/sockets-and-syslog.html
On Wed, Jun 8, 2011 at 6:29 AM, Raphael Päbst
wrote: Hey all! This is probably a question that shows my incompetence more than anything else, but I'm stuck with some TCP programming.
I have some code that looks like this:
hdl <- open TCP connection message <- hGetContents hdl answer <- do stuff with message hPut hdl answer hClose hdl
My problem is that the stuff that gets done with message happens, but only after I close the connection rom the client's side and then of course it is too late to get the answer out of said connection.
What am I doing wrong?
Many Thanks
Raf
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (4)
- 
                 aditya siram aditya siram
- 
                 Ertugrul Soeylemez Ertugrul Soeylemez
- 
                 Raphael Päbst Raphael Päbst
- 
                 Sean Perry Sean Perry