-
Notifications
You must be signed in to change notification settings - Fork 85
WebSocketListener options
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 settingTimeout.InfiniteTimeSpan
. -
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. Ifnull
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 singleByte[]
for different purpose data buffers, allocating/releasing this memory may be an issue (i.e.: making the GC to work too much) if your clients connect/disconnect too often. Its default value isnull
, what means that buffers will be created in the traditional way. Always indicate 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)