websockets-0.9.7.0: A sensible and clean way to write WebSocket-capable servers in Haskell.

Safe HaskellNone
LanguageHaskell98

Network.WebSockets.Connection

Description

This module exposes connection internals and should only be used if you really know what you are doing.

Synopsis

Documentation

data PendingConnection Source #

A new client connected to the server. We haven't accepted the connection yet, though.

Constructors

PendingConnection 

Fields

data AcceptRequest Source #

Constructors

AcceptRequest 

Fields

data Connection Source #

Constructors

Connection 

Fields

data ConnectionOptions Source #

Set options for a Connection.

Constructors

ConnectionOptions 

Fields

  • connectionOnPong :: !(IO ())

    Whenever a pong is received, this IO action is executed. It can be used to tickle connections or fire missiles.

receiveDataMessage :: Connection -> IO DataMessage Source #

Receive an application message. Automatically respond to control messages.

When the peer sends a close control message, an exception of type CloseRequest is thrown. The peer can send a close control message either to initiate a close or in response to a close message we have sent to the peer. In either case the CloseRequest exception will be thrown. The RFC specifies that the server is responsible for closing the TCP connection, which should happen after receiving the CloseRequest exception from this function.

This will throw ConnectionClosed if the TCP connection dies unexpectedly.

receiveData :: WebSocketsData a => Connection -> IO a Source #

Receive a message, converting it to whatever format is needed.

sendTextData :: WebSocketsData a => Connection -> a -> IO () Source #

Send a message as text

sendBinaryData :: WebSocketsData a => Connection -> a -> IO () Source #

Send a message as binary data

sendClose :: WebSocketsData a => Connection -> a -> IO () Source #

Send a friendly close message. Note that after sending this message, you should still continue calling receiveDataMessage to process any in-flight messages. The peer will eventually respond with a close control message of its own which will cause receiveDataMessage to throw the CloseRequest exception. This exception is when you can finally consider the connection closed.

sendCloseCode :: WebSocketsData a => Connection -> Word16 -> a -> IO () Source #

Send a friendly close message and close code. Similar to sendClose, you should continue calling receiveDataMessage until you receive a CloseRequest exception.

See http://tools.ietf.org/html/rfc6455#section-7.4 for a list of close codes.

sendPing :: WebSocketsData a => Connection -> a -> IO () Source #

Send a ping

forkPingThread :: Connection -> Int -> IO () Source #

Forks a ping thread, sending a ping message every n seconds over the connection. The thread dies silently if the connection crashes or is closed.