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

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. Ok, then pressing enter each time I want one of my servers to reply. I can
On Tuesday 20 December 2005 23:43, Einar Karttunen wrote: live with that.
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. Indeed.
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. Oh, new release, I am downloading it right now! So, I install a signal handler with installHandler... and then ? how do I prevent the program for quiting ? am I missing some kind of event loop here ?
ps. I think it may be best to continue on haskell-cafe@ rather than the main list. I am posting to there as well (to continue there). -- Pupeno
(http://pupeno.com)

On 21.12 01:13, Pupeno wrote:
So, I install a signal handler with installHandler... and then ? how do I prevent the program for quiting ? am I missing some kind of event loop here ?
Here is a small server program: main = performForkWithUnixySessionStuff work -- this is just for testing, replace with real implementation performForkWithUnixySessionStuff x = x work = do s1 <- runStreamServer ... s2 <- runDgramServer ... mv <- newEmptyMVar installHandler someSignal (Catch (putMVar mv ())) Nothing takeMVar mv someCleanupActions killServer s1 killServer s2 For simple testing you might want to just use getLine to wait for the right time to exit. - Einar Karttunen
participants (2)
-
Einar Karttunen
-
Pupeno