gdritter repos ucspi-hs / c8546b4
Added README Getty Ritter 9 years ago
1 changed file(s) with 44 addition(s) and 0 deletion(s). Collapse all Expand all
1 # ucspi-hs
2
3 [`UCSPI`](http://cr.yp.to/proto/ucspi.txt), or the Unix Client-Server
4 Program Interface, is a general interface designed for writing clients
5 and servers over some network interface. For a given protocol `xproto`,
6 there should exist `xprotoserver` and `xprotoclient` applications which
7 handle accepting and connecting to hosts, respectively, before executing
8 some Unix application. This is a (very small!) library to make writing
9 such applications simpler in Haskell.
10
11 One advantage to writing applications to the `UCSPI` interface is that
12 it becomes trivial to change the underlying network protocol being used
13 without modifying the application itself, by switching (for example)
14 from `tcpserver` to `sslserver`. Another is that very small, clean
15 network services can be written using these interfaces, because the
16 network-handling code is abstracted away.
17
18 ## Sample Client
19
20 A client which sends a single line to the server, receives a line
21 back, prints it to stdout, and exits looks like
22
23 ~~~~{.haskell}
24 import Network.UCSPI (ucspiClient)
25 import System.IO (hGetLine, hPutStrLn)
26
27 main :: IO ()
28 main = ucspiClient $ \ _ rdH wrH -> do
29 hPutStrLn wrH "hello"
30 ln <- hGetLine rdH
31 putStrLn ln
32 ~~~~
33
34 ## Sample Server
35
36 A server which receives a line from the client and sends back the
37 same line before closing the connection looks like
38
39 ~~~~{.haskell}
40 import Network.UCSPI (ucspiServer)
41
42 main :: IO ()
43 main = ucspiServer $ \ _ -> getLine >>= putstrLn
44 ~~~~