Holumbus-Distribution-0.1.1: intra- and inter-program communication

Portabilityportable
Stabilityexperimental
MaintainerStefan Schmidt (stefanschmidt@web.de)

Holumbus.Network.Communication

Contents

Description

Version : 0.1

This module implements an abstract client server model. The clients register at the server and check from time to time if the server still exists. If not, the client searches for a new server. The server on the other hand, keeps a list with all clients and checks, if each client is reachable. If not, the client is deleted from the list.

This abstract network model helps us to implement a basic distrubuted system with a central server and many attached clients which get little tasks from the server. Because this model alone would be very unfunctional, the user is able to define his own functions which will be handled by the server or the client.

Synopsis

Documentation

type StreamName = StringSource

The name of a stream.

data SocketId Source

All data, that is needed to address a socket. Contains the hostname and the portNumber.

time30 :: IntSource

30 seconds

time60 :: IntSource

60 seconds

timeIndefinitely :: IntSource

Wait how long it takes

type IdType = IntSource

The type of the client id.

data ClientInfo Source

Constructors

ClientInfo 

Fields

ci_Id :: Int
 
ci_Site :: SiteId

SiteId (Hostname,PID) of the client process

ci_Port :: ClientPort

the port of the client

ci_PingThreadId :: Thread

the threadId of the ping-Process (needed to stop it)

ci_LifeValue :: Int
 

Instances

server operations

data Server Source

The server.

Instances

Debug Server 
ServerClass Server 

newServerSource

Arguments

:: (Binary a, Binary b) 
=> StreamName 
-> Maybe PortNumber 
-> (a -> IO (Maybe b))

handling own request

-> Maybe RegistrationAction

for registration

-> Maybe RegistrationAction

for unregistration

-> IO Server 

Creates a new server.

closeServer :: Server -> IO ()Source

Closes the server.

data ServerPort Source

The ServerPort is only a wrapper for a Port-Datatype.

Instances

newServerPort :: StreamName -> Maybe SocketId -> IO ServerPortSource

Creates a new ServerPort.

sendRequestToServerSource

Arguments

:: (Show a, Binary a, Binary b) 
=> ServerPort 
-> Int 
-> a 
-> (b -> IO (Maybe c))

response handler

-> IO c 

Sends a request from the client to the server an handles the response or invokes a user-defined handler.

getClientInfo :: IdType -> Server -> IO (Maybe ClientInfo)Source

Gets the ClientPort from a ClientId (on the Server).

getAllClientInfos :: Server -> IO [ClientInfo]Source

Gets a list with all registered clients (on the Server).

client operations

class ClientClass c whereSource

The request-functions a client has to implement.

Methods

pingClient :: IdType -> c -> IO BoolSource

Check, if the client is responding.

getClientId :: c -> IO (Maybe IdType)Source

Get the ID of the client.

getServerPort :: c -> IO ServerPortSource

Gets the server port the client wants to connect to.

data ClientData Source

Client datatype.

Constructors

ClientData 

Fields

cd_ServerThreadId :: Thread
 
cd_PingThreadId :: Thread
 
cd_Id :: Maybe IdType
 
cd_LifeValue :: Int
 
cd_SiteId :: SiteId
 
cd_OwnStream :: Stream ClientRequestMessage
 
cd_OwnPort :: Port ClientRequestMessage
 
cd_ServerPort :: ServerPort
 

data Client Source

Only a wrapper around an MVar.

Constructors

Client (MVar ClientData) 

newClientSource

Arguments

:: (Binary a, Binary b) 
=> StreamName 
-> Maybe SocketId 
-> (a -> IO (Maybe b))

the individual request dispatcher for the client -- (ReqM -> IO (RespM)

-> IO Client 

Creates a new client, it needs the StreamName and optional the SocketId of the server.

closeClient :: Client -> IO ()Source

Closes the client.

data ClientPort Source

Just a wrapper around a port.

Constructors

ClientPort (Port ClientRequestMessage) 

sendRequestToClientSource

Arguments

:: (Show a, Binary a, Binary b) 
=> ClientPort 
-> Int 
-> a 
-> (b -> IO (Maybe c))

response handler

-> IO c 

Sends a request from the server to the client an handles the response or invokes a user-defined handler.