ยค tSocketServerF, tTransceiverF, et al

Client/Server programming

Types

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)

Synopsis

tSocketServerF port clienthandler

data ClientMsg a = ClientMsg a | ClientEOS | ClientNew
data SocketMsg a = SocketMsg a | SocketEOS

Description

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.

Input

pairs of client numbers and messages to send to a client handler.

Output

pairs of client numbers and messages concerning a client. (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.

Arguments

port :: TPort c s
The port number to listen for connections at.

clienthandler :: Peer -> F s (SocketMsg c) -> F a (SocketMsg b)
A fudget that handles the communication with one client. The fudget has two parameters: the peer name and the transciever fudget for communicating with the client. The simplest possible handler is \ peer transceiver -> transceiver.

Examples

The Chat and Calendar demos distributed with the fudget library illustrates the use of these fudgets.

See Also

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).

Bugs

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.