[Haskell] A simple server (or how to do io).

Pupeno pupeno at pupeno.com
Tue Dec 20 19:52:30 EST 2005

I have written a simple Daytime sever using network-alt[1] (I am sorry if this 
is off topic, is it ?)
The server is:

server port = do
  runStreamServer (nullStreamServer {handlerSS = sendDaytime, servSS = port})

sendDaytime = handlerWithHandle $ \hs sa -> do
  putStrLn (show sa)
  hSetBuffering hs LineBuffering
  time <- Time.getClockTime
  hPutStrLn hs (show time)
  hClose hs

It works, but I have the following problems:
When I run server "10013" from ghci, the prompt returns immediately and if I 
do a query to that port I don't get anything, until I go and press enter on 
ghci and the daytime is sent to the client. Like if the prompt was blocking 
all IO or something like that.
The other problem is that I tried to make a program, so I made 

main = do
  server "10013"

I compile it and run it. It returns immediately and the server of course, is 
not running.
I think what I am missing is that server, after running runStreamServer should 
block and be able to reply to all the queries (in the final version I'll also 
have runDgramServer as well) and be able to receive a signal, upon which it 
should close the socket and finish. How can do that ? Any help will be 
Thank you.
Pupeno <pupeno at pupeno.com> (http://pupeno.com)

[1] http://www.cs.helsinki.fi/u/ekarttun/network-alt/ I am currently using the 
select mode.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.haskell.org//pipermail/haskell/attachments/20051220/b8dc8801/attachment.bin

More information about the Haskell mailing list