Provides a generic TCP server, parameterized over the server's listening port and the types of messages received from and sent to clients.
- tcpServer :: Show a => ServerPortNumber -> TCPMessageDriver a b -> IO [Peer a b]
- type ServerPortNumber = Word16
- data TCPMessageDriver a b = TCPMessageDriver {
- getMessage :: Handle -> IO (Maybe a)
- putMessage :: b -> Handle -> IO ()
- type Peer a b = (SockAddr, Process a b IOException)
- data Process a b c = Process {}
- readAll :: Process a b c -> IO [a]
- writeAll :: Process a b c -> [b] -> IO ()
- data SockAddr
Documentation
tcpServer :: Show a => ServerPortNumber -> TCPMessageDriver a b -> IO [Peer a b]Source
tcpServer starts a TCP server at the given port number, waiting for new connections. Whenever a new connection is established, new threads are created for reading and writing to the thread, using the given tcp message driver. The socket address of the other side of the connection, along with a pair of channels for the incoming messages and outgoing messages is placed on the result channel. This method returns immediately.
type ServerPortNumber = Word16Source
data TCPMessageDriver a b Source
A TCPMessageDriver a b
is used by the tcpServer
to read messages of type a
from the underlying TCP sockets with
peers as well as write messages of type b
to the TCP sockets.
TCPMessageDriver | |
|
type Peer a b = (SockAddr, Process a b IOException)Source
A Peer is a TCP peer. It consists of a SockAddr
value giving the
the socket address of the peer, as well as a Process
value which provides methods to access
messages received from the peer and send messages to a peer.
A Process a b c
represents a process with an API that
allows another IO computation to observe its outputs (of type a
), to
supply it with inputs (of type b
), and to observe when it terminates.
Process | |
|