Safe Haskell | None |
---|
- type CmdHandler = [String] -> Server -> ClientConn -> IO ()
- type ConnectionHandler = Server -> ClientConn -> IO ()
- type DisconnectHandler = Server -> ClientConn -> IO ()
- data ClientConn
- data Server
- new :: ConnectionHandler -> DisconnectHandler -> Int -> IO Server
- addCommand :: Server -> String -> CmdHandler -> IO ()
- start :: Server -> IO ()
- stop :: Server -> IO ()
- respond :: ClientConn -> String -> IO ()
- broadcast :: Server -> String -> IO ()
- disconnectClient :: Server -> ClientConn -> IO ()
- clientList :: Server -> IO [ClientConn]
Documentation
type CmdHandler = [String] -> Server -> ClientConn -> IO ()Source
A CmdHandler is used to handle a command in the form of a list of strings
type ConnectionHandler = Server -> ClientConn -> IO ()Source
A ConnectionHandler is called each time a client connects to the server.
type DisconnectHandler = Server -> ClientConn -> IO ()Source
A DisconnectHandler is called each time a client is disconnected from the server.
data ClientConn Source
Describes a Clients connection and provides an interface for storing data associated with the client. Each client will be given a unique cid and are Eq if their cid's are Eq.
A ClientConn comes packaged with two functions for storing additional
information in Strings. lookup
and modify
. The lookup function
takes a key and returns the current value of the key or the empty
string if it has never been set. The modify function
takes a key and value and updates it such that the next call to
lookup with that key will return the value provided.
new :: ConnectionHandler -> DisconnectHandler -> Int -> IO ServerSource
Creates a new server that is not connected to anything. If a client does not talk to a server for more than 60 seconds it will be disconnected.
addCommand :: Server -> String -> CmdHandler -> IO ()Source
Given a server, a command, and a command handler, adds the command to the server. If the command already exists, it will be overwritten
start :: Server -> IO ()Source
Starts a server if it is currently not started. Otherwise, does nothing.
Stops a server if it is running sending a disconnect message to all clients. Otherwise, does nothing. Any shutdown operations should be run before this is called.
respond :: ClientConn -> String -> IO ()Source
Adds a response message to the queue.
disconnectClient :: Server -> ClientConn -> IO ()Source
Disconnects the client if they are on this server. If they are not on this server, the results are unspecified.
clientList :: Server -> IO [ClientConn]Source
Returns a list of all clients that are currently connected to the server