Safe Haskell | None |
---|---|
Language | Haskell98 |
This module exposes connection internals and should only be used if you really know what you are doing.
Synopsis
- data PendingConnection = PendingConnection {
- pendingOptions :: !ConnectionOptions
- pendingRequest :: !RequestHead
- pendingOnAccept :: !(Connection -> IO ())
- pendingStream :: !Stream
- acceptRequest :: PendingConnection -> IO Connection
- data AcceptRequest = AcceptRequest {
- acceptSubprotocol :: !(Maybe ByteString)
- acceptHeaders :: !Headers
- defaultAcceptRequest :: AcceptRequest
- acceptRequestWith :: PendingConnection -> AcceptRequest -> IO Connection
- rejectRequest :: PendingConnection -> ByteString -> IO ()
- data RejectRequest = RejectRequest {
- rejectCode :: !Int
- rejectMessage :: !ByteString
- rejectHeaders :: Headers
- rejectBody :: !ByteString
- defaultRejectRequest :: RejectRequest
- rejectRequestWith :: PendingConnection -> RejectRequest -> IO ()
- data Connection = Connection {
- connectionOptions :: !ConnectionOptions
- connectionType :: !ConnectionType
- connectionProtocol :: !Protocol
- connectionParse :: !(IO (Maybe Message))
- connectionWrite :: !([Message] -> IO ())
- connectionSentClose :: !(IORef Bool)
- data ConnectionOptions = ConnectionOptions {}
- defaultConnectionOptions :: ConnectionOptions
- receive :: Connection -> IO Message
- receiveDataMessage :: Connection -> IO DataMessage
- receiveData :: WebSocketsData a => Connection -> IO a
- send :: Connection -> Message -> IO ()
- sendDataMessage :: Connection -> DataMessage -> IO ()
- sendDataMessages :: Connection -> [DataMessage] -> IO ()
- sendTextData :: WebSocketsData a => Connection -> a -> IO ()
- sendTextDatas :: WebSocketsData a => Connection -> [a] -> IO ()
- sendBinaryData :: WebSocketsData a => Connection -> a -> IO ()
- sendBinaryDatas :: WebSocketsData a => Connection -> [a] -> IO ()
- sendClose :: WebSocketsData a => Connection -> a -> IO ()
- sendCloseCode :: WebSocketsData a => Connection -> Word16 -> a -> IO ()
- sendPing :: WebSocketsData a => Connection -> a -> IO ()
- forkPingThread :: Connection -> Int -> IO ()
- data CompressionOptions
- data PermessageDeflate = PermessageDeflate {}
- defaultPermessageDeflate :: PermessageDeflate
- data SizeLimit
Documentation
data PendingConnection Source #
A new client connected to the server. We haven't accepted the connection yet, though.
PendingConnection | |
|
acceptRequest :: PendingConnection -> IO Connection Source #
Accept a pending connection, turning it into a Connection
.
data AcceptRequest Source #
This datatype allows you to set options for acceptRequestWith
. It is
strongly recommended to use defaultAcceptRequest
and then modify the
various fields, that way new fields introduced in the library do not break
your code.
AcceptRequest | |
|
acceptRequestWith :: PendingConnection -> AcceptRequest -> IO Connection Source #
This function is like acceptRequest
but allows you to set custom options
using the AcceptRequest
datatype.
:: PendingConnection | Connection to reject |
-> ByteString | Rejection response body |
-> IO () |
data RejectRequest Source #
Parameters that allow you to tweak how a request is rejected. Please use
defaultRejectRequest
and modify fields using record syntax so your code
will not break when new fields are added.
RejectRequest | |
|
:: PendingConnection | Connection to reject |
-> RejectRequest | Params on how to reject the request |
-> IO () |
data Connection Source #
Connection | |
|
data ConnectionOptions Source #
Set options for a Connection
. Please do not use this constructor
directly, but rather use defaultConnectionOptions
and then set the fields
you want, e.g.:
myOptions = defaultConnectionOptions {connectionStrictUnicode = True}
This way your code does not break if the library introduces new fields.
ConnectionOptions | |
|
defaultConnectionOptions :: ConnectionOptions Source #
The default connection options:
- Nothing happens when a pong is received.
- Compression is disabled.
- Lenient unicode decoding.
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.
sendDataMessage :: Connection -> DataMessage -> IO () Source #
Send a DataMessage
. This allows you send both human-readable text and
binary data. This is a slightly more low-level interface than sendTextData
or sendBinaryData
.
sendDataMessages :: Connection -> [DataMessage] -> IO () Source #
Send a collection of DataMessage
s. This is more efficient than calling
sendDataMessage
many times.
sendTextData :: WebSocketsData a => Connection -> a -> IO () Source #
Send a textual message. The message will be encoded as UTF-8. This should be the default choice for human-readable text-based protocols such as JSON.
sendTextDatas :: WebSocketsData a => Connection -> [a] -> IO () Source #
Send a number of textual messages. This is more efficient than calling
sendTextData
many times.
sendBinaryData :: WebSocketsData a => Connection -> a -> IO () Source #
Send a binary message. This is useful for sending binary blobs, e.g. images, data encoded with MessagePack, images...
sendBinaryDatas :: WebSocketsData a => Connection -> [a] -> IO () Source #
Send a number of binary messages. This is more efficient than calling
sendBinaryData
many times.
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.
This is useful to keep idle connections open through proxies and whatnot. Many (but not all) proxies have a 60 second default timeout, so based on that sending a ping every 30 seconds is a good idea.
data CompressionOptions Source #
Instances
Eq CompressionOptions Source # | |
Defined in Network.WebSockets.Connection.Options (==) :: CompressionOptions -> CompressionOptions -> Bool # (/=) :: CompressionOptions -> CompressionOptions -> Bool # | |
Show CompressionOptions Source # | |
Defined in Network.WebSockets.Connection.Options showsPrec :: Int -> CompressionOptions -> ShowS # show :: CompressionOptions -> String # showList :: [CompressionOptions] -> ShowS # |
data PermessageDeflate Source #
Four extension parameters are defined for "permessage-deflate" to help endpoints manage per-connection resource usage.
- "server_no_context_takeover"
- "client_no_context_takeover"
- "server_max_window_bits"
- "client_max_window_bits"
Instances
Eq PermessageDeflate Source # | |
Defined in Network.WebSockets.Connection.Options (==) :: PermessageDeflate -> PermessageDeflate -> Bool # (/=) :: PermessageDeflate -> PermessageDeflate -> Bool # | |
Show PermessageDeflate Source # | |
Defined in Network.WebSockets.Connection.Options showsPrec :: Int -> PermessageDeflate -> ShowS # show :: PermessageDeflate -> String # showList :: [PermessageDeflate] -> ShowS # |