Portability | portable |
---|---|
Stability | experimental |
Maintainer | Stefan Schmidt (stefanschmidt@web.de) |
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.
- type StreamName = String
- data SocketId
- data PortNumber
- time30 :: Int
- time60 :: Int
- timeIndefinitely :: Int
- type IdType = Int
- data ClientInfo = ClientInfo {
- ci_Id :: Int
- ci_Site :: SiteId
- ci_Port :: ClientPort
- ci_PingThreadId :: Thread
- ci_LifeValue :: Int
- data Server
- newServer :: (Binary a, Binary b) => StreamName -> Maybe PortNumber -> (a -> IO (Maybe b)) -> Maybe RegistrationAction -> Maybe RegistrationAction -> IO Server
- closeServer :: Server -> IO ()
- data ServerPort
- newServerPort :: StreamName -> Maybe SocketId -> IO ServerPort
- sendRequestToServer :: (Show a, Binary a, Binary b) => ServerPort -> Int -> a -> (b -> IO (Maybe c)) -> IO c
- getClientInfo :: IdType -> Server -> IO (Maybe ClientInfo)
- getAllClientInfos :: Server -> IO [ClientInfo]
- class ClientClass c where
- pingClient :: IdType -> c -> IO Bool
- getClientId :: c -> IO (Maybe IdType)
- getServerPort :: c -> IO ServerPort
- data ClientData = ClientData {
- 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 = Client (MVar ClientData)
- newClient :: (Binary a, Binary b) => StreamName -> Maybe SocketId -> (a -> IO (Maybe b)) -> IO Client
- closeClient :: Client -> IO ()
- data ClientPort = ClientPort (Port ClientRequestMessage)
- sendRequestToClient :: (Show a, Binary a, Binary b) => ClientPort -> Int -> a -> (b -> IO (Maybe c)) -> IO c
Documentation
type StreamName = StringSource
The name of a stream.
All data, that is needed to address a socket. Contains the hostname and the portNumber.
data PortNumber
Wait how long it takes
data ClientInfo Source
ClientInfo | |
|
server operations
:: (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.
Show ServerPort | |
Binary ServerPort | |
ServerClass ServerPort |
newServerPort :: StreamName -> Maybe SocketId -> IO ServerPortSource
Creates a new ServerPort.
:: (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.
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.
ClientData | |
|
Only a wrapper around an MVar.
:: (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.