tSocketServerF :: (Read c, Show s) => TPort c s -> (Peer -> F s (SocketMsg c) -> F a (SocketMsg b)) -> F (Int, a) (Int, ClientMsg b) tTransceiverF :: (Show c, Read s) => TServerAddress c s -> F c (SocketMsg s) data TPort a b = TPort Port tPort :: (Show a, Read a, Show b, Read b) => Port -> TPort a b data TServerAddress c s = TServerAddress Host (TPort c s)
tSocketServerF port clienthandler
data ClientMsg a = ClientMsg a | ClientEOS | ClientNew
data SocketMsg a = SocketMsg a | SocketEOS
There are fudgets for type safe client/server programming. tSocketServerF
is used to
implement servers, tTransceiverF
is used to implement clients.
To ensure type safe communication, a port with a specific (monomorphic) type
should be defined, using tPort
in a module common to the client and
the server.
(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 :: TPort c s
clienthandler :: Peer -> F s (SocketMsg c) -> F a (SocketMsg b)
\ peer transceiver -> transceiver
.
The Chat
and Calendar
demos distributed with the fudget library
illustrates the use of these fudgets.
Untyped socket communication: socketServerF, transceiverF.
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 Client/Server Applications with Fudgets (1994).
Values are transfered by converting them to strings, using the methods of
the Show
and Read
classes. These are usually not very efficient.
The show
method mustn't use the newline character, since it is used to
separate messages in the stream. (Derrived Show
instances comply
with this.)
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.