Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
WebSocketListener accepts an object with several options:
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
PingModes): There are two main strategies, the default
PingModes.LatencyControlthat sends ping frames with time frames in a regular interval and calculates the latency of the connection with those. The alternative
PingModes.BandwidthSavingthat only sends empty ping frames when the connection has been inactive for portion of the
PingTimeout, and do not calculate connection latency.
Int32): The amount of TCP connections that are accepted and queued before doing the WebSocket handshake. Default:
Environment.ProcessorCount * 10
Int32?): The TCP backlog. If
nullit will use the platform default. Default:
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.
TimeSpan): The timeout for the WebSocket handshake. Default: 5 seconds.
TimeSpan): The TCP send timeout. Default: 5 seconds.
TimeSpan): The TCP receive timeout. Default: 5 seconds.
Int32): The send buffer. Default: 8192.
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:
OnHttpNegotiationDelegate): Allows to hook into the HTTP negotiation and add/check cookies and/or return a custom HTTP status code. More info.
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): 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
Bytefor 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)