-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple Server interface -- -- This library provides a very simple interface for creating a server -- that sends and recieves ByteString messages and attempts to remove -- concurrency so the programmer can focus on the functionality of the -- server. A simple ChatServer example is available in the Examples -- module @package simple-server @version 0.0.2 module Network.SimpleServer.Examples.ChatClient main :: IO () run :: HostName -> Int -> IO () -- | The goal of SimpleServer, as its name implies, is to make it easy to -- build simple message passing servers by puting a layer between the -- programmer and the concurrent operations between it and the network -- layer connecting it to multiple clients. module Network.SimpleServer -- | Each server has one ConnectionHandler that is called each time a -- client connects to the server. type ConnectionHandler = Server -> ClientConn -> IO () -- | A DisconnectHandler is called each time a client is disconnected from -- the server. type DisconnectHandler = Server -> ClientConn -> IO () -- | A server may have any number of CmdHandlers. When a CmdHandler is -- called it is passed a list of strings representing the message the -- server received, the server that received it, and the client that send -- the message. The first part element of the list is the string that -- triggered the CmdHandler. type CmdHandler = [String] -> Server -> ClientConn -> IO () -- | A Simple Server data Server -- | Creates a new server with the specified ConnectionHandler and -- DisconnectHandler. On a call to start, the server will attempt to -- connect on the specified Port. If a client does not talk to a server -- for more than 60 seconds it will be disconnected. new :: ConnectionHandler -> DisconnectHandler -> Int -> IO Server -- | Given a server, a command, and a command handler, adds the command to -- the server. If the command already exists, it will be overwritten. addCommand :: Server -> String -> CmdHandler -> IO () -- | Starts a server if it is currently not started. Otherwise, does -- nothing. The server will be started on a new thread and control will -- be returned to the thread that called this function. start :: Server -> IO () -- | Stops a server if it is running sending a disconnect message to all -- clients and killing any threads that have been spawned. Otherwise, -- does nothing. Any shutdown operations should be run before this is -- called. stop :: Server -> IO () -- | 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. data ClientConn -- | The Unique ID for this client cid :: ClientConn -> Integer -- | Looks up a property for this client. By default, all properties are -- the empty string. lookup :: ClientConn -> (String -> IO String) -- | Modifies a client property. Given a property string, and a value -- string, the next call to lookup for the given property will result in -- the value. modify :: ClientConn -> (String -> String -> IO ()) -- | Adds a message to the clients message queue to be handled eventually. respond :: ClientConn -> String -> IO () -- | Adds a message to all clients message queue to be handled eventually. broadcast :: Server -> String -> IO () -- | Disconnects the client if they are still connected to the server. disconnect :: ClientConn -> IO () -- | Returns a list of all clients that are currently connected to the -- server clientList :: Server -> IO [ClientConn] instance Eq Message instance Eq ClientConn module Network.SimpleServer.Examples.ChatServer main :: IO () run :: Int -> IO ()