socketServerF :: Int -> (Socket -> Peer -> F a1 (SocketMsg a2)) -> F (Int, a1) (Int, ClientMsg a2) data SocketMsg a = SocketMsg a | SocketEOS instance Functor SocketMsg instance Show a => Show (SocketMsg a) data ClientMsg a = ClientMsg a | ClientEOS | ClientNew instance Show a => Show (ClientMsg a)
socketServerF port clienthandler
type Port = Int
type Peer = Host
socketServerF
creates a socket server, that is, a fudget that creates a passive socket
and waits for other programs, clients, to connect to it. When a new client
connects, it is assigned a unique number and a handler fudget is started to
communicate with it.
Client handlers can communicate both with the (remote) client and with (local) fudgets connected to the server fudget. A client handler can thus be very simple, and just forward messages to other fudgets, or it can be more complex and can handle most (or all) of the communication with the client on its own.
(n,ClientNew)
, where n
is a new number, is output when
a new client connects.
(n,ClientMsg x)
is output when the handler for
client n
outputs SocketMsg x
.
(n,ClientEOS)
is output when the client handler outputs
SocketEOS
. After this, the client handler is terminated.
port :: Int
clienthandler :: Socket -> Peer -> F a1 (SocketMsg a2)
Connecting to a server from a client: openSocketF.
A fudget for creating clients and client handlers handlers: transceiverF.
Type safe socket communication: tSocketServerF et al.
A more detailed description of the ideas can be found in the chapter Typed sockets for client/server applications of the Fudgets Thesis .
The first presentation of the ideas appeared in Implementing Real-time Interactive Multi-User Games with Fudgets (1994).
SocketMsg
,
but transceiverF outputs messages of type String
.
This page documents work progress. Information on this page is subject to change without notice and does not represent a commitment on the part of the Fudgets corporation.