HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulewebsockets-0.13.0.0Haskell2010

Network.WebSockets.Connection

This module exposes connection internals

  • 8 types
  • 25 values
datadata AcceptRequest
#

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.

Constructors

datadata Connection
#

Constructors

datadata ConnectionOptions
#

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.

Constructors

  • ConnectionOptions
    • connectionOnPong :: !IO ()

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

    • connectionTimeout :: !Int

      Timeout for connection establishment in seconds. Only used in the client.

    • connectionCompressionOptions :: !CompressionOptions
    • connectionStrictUnicode :: !Bool

      Enable strict unicode on the connection. This means that if a client (or server) sends invalid UTF-8, we will throw a UnicodeException rather than replacing it by the unicode replacement character U+FFFD.

    • connectionFramePayloadSizeLimit :: !SizeLimit

      The maximum size for incoming frame payload size in bytes. If a frame exceeds this limit, a ParseException is thrown.

    • connectionMessageDataSizeLimit :: !SizeLimit

      connectionFrameSizeLimit is often not enough since a malicious client can send many small frames to create a huge message. This limit allows you to protect from that. If a message exceeds this limit, a ParseException is thrown.

      Note that, if compression is enabled, we check the size of the compressed messages, as well as the size of the uncompressed messages as we are deflating them to ensure we don't use too much memory in any case.

The default connection options:

  • Nothing happens when a pong is received.

  • Compression is disabled.

  • Lenient unicode decoding.

  • 30 second timeout for connection establishment.

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.

valuesendTextData :: WebSocketsData a => Connection -> a -> IO ()
#

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.

valuesendClose :: WebSocketsData a => Connection -> a -> IO ()
#

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.

valuewithPingThread
  1. :: Connection
  2. -> Int

    Second interval in which pings should be sent.

  3. -> IO ()

    Repeat this after sending a ping.

  4. -> IO a

    Application to wrap with a ping thread.

  5. -> IO a

    Executes application and kills ping thread when done.

#

Forks a ping thread, sending a ping message every n seconds over the connection. The thread is killed when the inner IO action is finished.

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.

Note that usually you want to use withPingPong to timeout the connection if a pong is not received.

valueforkPingThread :: Connection -> Int -> IO ()
#

Deprecated. Use withPingThread instead

DEPRECATED: Use withPingThread instead.

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.

datadata PermessageDeflate
#

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"

Instances2Eq, Show
datadata SizeLimit
#

A size limit, in bytes. The Monoid instance takes the minimum limit.

Instances4Eq, Show, Semigroup, Monoid
  • Eq SizeLimitDefined in websockets-0.13.0.0 · Network.WebSockets.Connection.Options
  • Show SizeLimitDefined in websockets-0.13.0.0 · Network.WebSockets.Connection.Options
  • Semigroup SizeLimitDefined in websockets-0.13.0.0 · Network.WebSockets.Connection.Options
  • Monoid SizeLimitDefined in websockets-0.13.0.0 · Network.WebSockets.Connection.Options