Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Server
- data Args = Args {
- host :: String
- portNumber :: Int
- type RequestHandler = ByteString -> IO (Maybe ByteString)
- start :: Args -> IO Server
- reinit :: Server -> IO ()
- threadId :: Server -> ThreadId
- enqueRequestHandler :: Server -> RequestHandler -> IO ()
- enqueResponse :: Server -> ByteString -> IO ()
- replaceRequestHandlers :: Server -> [RequestHandler] -> IO ()
- setDefaultRequestHandler :: Server -> RequestHandler -> IO ()
- setDefaultResponse :: Server -> ByteString -> IO ()
- respondWith :: ByteString -> RequestHandler
- doNothing :: RequestHandler
- sendToClients :: Server -> ByteString -> IO ()
- forgetDefaultRequestHandler :: Server -> IO ()
- forgetDefaultResponse :: Server -> IO ()
- forgetReceivedRequests :: Server -> IO ()
- listeningPort :: Server -> Int
- listeningHost :: Server -> String
- recentlyReceived :: Server -> IO (Deque ByteString)
- countConnectedClients :: Server -> IO Int
The server object type and related types.
The Server object.
You can easily configure the behavior (how the server responds with some requests)
after creating by start
function.
type RequestHandler = ByteString -> IO (Maybe ByteString) Source #
Used to configure the server's behavior when receiving DataMessage
as a ByteString
.
If returns Nothing
, the server does nothing.
Controling the server's lifecycle.
start :: Args -> IO Server Source #
Start the server by the given hostname and port number as Args
object.
reinit :: Server -> IO () Source #
Close all connections, forget recently received requests,
and delete any configured RequestHandler
s.
Configuring how the server responds/sends WebSocket messages to the client.
enqueRequestHandler :: Server -> RequestHandler -> IO () Source #
Configure the request handler called when the server receives next.
RequestHandler
s configured with this function and other non-Default
functions are "dequeued".
So the server responds with the request handler only once.
If you need the server to respond always with the same response,
use setDefaultResponse
and setDefaultRequestHandler
.
enqueResponse :: Server -> ByteString -> IO () Source #
Configure the response called when the server receives next.
replaceRequestHandlers :: Server -> [RequestHandler] -> IO () Source #
Reset the request handler queue.
setDefaultRequestHandler :: Server -> RequestHandler -> IO () Source #
Configure the request handler called when no request handlers are queued.
setDefaultResponse :: Server -> ByteString -> IO () Source #
Configure the response called when no request handlers are queued.
respondWith :: ByteString -> RequestHandler Source #
Maybe often used RequestHandler
. Always respond with the given Message
.
doNothing :: RequestHandler Source #
Maybe often used RequestHandler
. Do nothing.
sendToClients :: Server -> ByteString -> IO () Source #
Send the given Message
immediately to the all connected clients.
forgetDefaultRequestHandler :: Server -> IO () Source #
Delete the default request handler. After calling this function,
the Server
object doesn't respond to any message if the request handler queue is empty.
forgetDefaultResponse :: Server -> IO () Source #
Alias for forgetDefaultRequestHandler
forgetReceivedRequests :: Server -> IO () Source #
Forget recently received requests.
Checking the server's status.
listeningPort :: Server -> Int Source #
listeningHost :: Server -> String Source #
recentlyReceived :: Server -> IO (Deque ByteString) Source #
Retrieve any messages sent by the clients.