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

Einar Karttunen ekarttun at cs.helsinki.fi
Tue Dec 20 21:43:34 EST 2005

On 20.12 21:52, Pupeno wrote:
> 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 
> DaytimeServer.hs:

Your problem is that the ghci prompt *is* blocking everything. ghci is
builded non-threaded. Ghci uses a blocking call to read the lines
which means that all other computations are stopped.

> I compile it and run it. It returns immediately and the server of course, is 
> not running.

It spawns the server threads and returns immediately.

> 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 
> appreciated.

Catch the signal and kill the listening threads. If you
are using the new 0.3.1 release then you can use the
killServer call.

ps. I think it may be best to continue on haskell-cafe@ rather 
than the main list.

- Einar Karttunen

More information about the Haskell mailing list