client/server library

Hal Daume III hdaume@ISI.EDU
Fri, 1 Mar 2002 09:53:48 -0800 (PST)


I'm wondering if anyone has written anything akin to a client/server
library which is based on sockets, something along the lines of:

> mkServer :: Int -> (String -> String) -> IO ()

so I could then say:

> module MyServer where
> 
> main = mkServer portNum myServerFn
> 
> myServerFn "getname" = "This server's name is Bob"
> myServerFn _ = "Unknown command"

and

> data Server = ...
> serverConnect :: Int -> IO Server
> queryServer :: Server -> String -> IO String
> serverDisconnect :: Server -> IO ()

so I could write:

> module MyClient where
>
> main =
>     do s <- serverConnect portNum
>        res <- queryServer "getname"
>        putStrLn res
>        serverDisconnect s

and this would print "This server's name is Bob".

I don't imagine such a "library" would be difficult to write; it would
mostly be wrapping around the Socket library (the assumption would be that
the server and client would both be running on the same machine).  But it
would need to be robust (i.e., the server should my multithreaded among
other things), etc.

I could probably figure out how to write some such thing, but if someone
else who knows more about the net and concurrent packages already has (I
know nothing), I'd love to steal their code :)

 - Hal


--
Hal Daume III

 "Computer science is no more about computers    | hdaume@isi.edu
  than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume