WebSocketListener options

Val edited this page Jun 1, 2016 · 24 revisions

WebSocketListener accepts an object with several options:

  • PingTimeout (TimeSpan): The amount of time the WebSocket will wait without receiving a "ping" response ("pong") before disconnecting by inactivity. "Pings" are sent with a PingTimeout/3 interval. Default: 5 seconds. Can be disabled by setting Timeout.InfiniteTimeSpan.

  • PingMode (PingModes): There are two main strategies, the default PingModes.LatencyControl that sends ping frames with time frames in a regular interval and calculates the latency of the connection with those. The alternative PingModes.BandwidthSaving that only sends empty ping frames when the connection has been inactive for portion of the PingTimeout, and do not calculate connection latency.

  • NegotiationQueueCapacity (Int32): The amount of TCP connections that are accepted and queued before doing the WebSocket handshake. Default: Environment.ProcessorCount * 10

  • TcpBacklog (Int32?): The TCP backlog. If null it will use the platform default. Default: null.

  • ParallelNegotiations (Int32): The amount of parallel WebSocket handshakes that can be done. In some situations, like when using TLS, this process could be slower because it needs more round trips, and increment this value can improve the performance. Default: Environment.ProcessorCount * 2.

  • NegotiationTimeout (TimeSpan): The timeout for the WebSocket handshake. Default: 5 seconds.

  • WebSocketSendTimeout (TimeSpan): The TCP send timeout. Default: 5 seconds.

  • WebSocketReceiveTimeout (TimeSpan): The TCP receive timeout. Default: 5 seconds.

  • SendBufferSize (Int32): The send buffer. Default: 8192.

  • SubProtocols (String[]): The allowed sub protocols. If the client requests a sub protocol, the first match from the request and this collection will be used, if there is not match an exception will be thrown cancelling the handshake. Default: String[0].

  • OnHttpNegotiation (OnHttpNegotiationDelegate): Allows to hook into the HTTP negotiation and add/check cookies and/or return a custom HTTP status code. More info.

  • UseNagleAlgorithm (Boolean?): Allows to enable/disable the Nagle's Algorithm. This algorithm, enabled by default in Windows sockets, increases bandwidth efficiency at the expense of latency. If your application uses small messages and has real time needs, you may consider disabling it. Use with care, and always do some analysis to ensure you are not making things worse. Default: null (will preserve system default).

  • BufferManager (BufferManager): This property allows to set a BufferManager that will be responsible of creating the memory associated with each WebSocket connection. Each connection uses a single Byte[] for different purpose data buffers, allocating/releasing this memory may be an issue if your clients connect/disconnect too often (i.e.: making the GC to work too much). Its default value is null, what means that buffers will be created in the traditional way. Always set SendBufferSize + 1KB. For example, if your SendBufferSize is 8KB, and your expected connection average is about 2000 clients, you may use:

BufferManager = BufferManager.CreateBufferManager((8192 + 1024) * 2000, 8192 + 1024)
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.