websockets-0.1.2.5: Server-side WebSocket protocol handshake and communication.

Network.WebSockets

Synopsis

Documentation

shakeHands :: Handle -> IO (Either String Request)Source

Accept and perform a handshake, no matter the request contents.

As long as the request is well-formed, the client will receive a response saying, essentially, "proceed". Use this function if you don't care who you're connected to, as long as that someone speaks the WebSocket protocol.

The function returns either a String in case of error, or a Request on success. The Request is returned purely for logging purposes, since the handshake has already been executed. Use this function immediately after establishing the WebSocket connection.

If you wish not to blindly accept requests but to filter them according to their contents, use the getRequest and putResponse functions.

getRequest :: Handle -> IO (Either String Request)Source

Reads the client's opening handshake and returns either a Request based on its contents, or a String in case of an error.

putResponse :: Handle -> Request -> IO ()Source

Sends an accepting response based on the given Request, thus accepting and ending the handshake.

getFrame :: Handle -> IO ByteStringSource

Receive a strict ByteString. Call this function only after having performed the handshake. This function will block until an entire frame is read. If the writing end of the handle is closed, the function returns an empty ByteString.

putFrame :: Handle -> ByteString -> IO ()Source

Send a strict ByteString. Call this function only after having performed the handshake.

reqHost :: Request -> StringSource

Returns the requested host.

reqPath :: Request -> StringSource

Returns the requested path.

reqOrigin :: Request -> StringSource

Returns the origin of the request.

reqLocation :: Request -> StringSource

Returns the requested location. Equal to (\r -> "ws://" ++ reqHost r ++ reqPath r).

data Request Source

Contains the request details, accessible via the reqHost, reqPath, reqOrigin and reqLocation functions.

Instances