skews-0.1.0.1: A very quick-and-dirty WebSocket server.

Safe HaskellNone
LanguageHaskell2010

Network.WebSockets.Skews

Contents

Synopsis

The server object type and related types.

data Server Source #

The Server object. You can easily configure the behavior (how the server responds with some requests) after creating by start function.

data Args Source #

Constructors

Args 

Fields

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 RequestHandlers.

threadId :: Server -> ThreadId Source #

Call killThread to stop the server.

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. RequestHandlers 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.

forgetReceivedRequests :: Server -> IO () Source #

Forget recently received requests.

Checking the server's status.

recentlyReceived :: Server -> IO (Deque ByteString) Source #

Retrieve any messages sent by the clients.