class WebSocket
A WebSocket client for connecting to external services.
Remarks: Events handlers will be called on the synchronization context that Connect was called on.
public bool IsConnected { get; }
Returns true as long as a WebSocket connection is established.
public string SubProtocol { get; }
Get the sub-protocol that was negotiated during the opening handshake.
public bool EnableCompression { set; }
Enable or disable compression for the websocket. If the server supports it, compression will be enabled for all messages. Note: compression is disabled by default, and can be dangerous if you are sending secrets across the network.
public WebSocket( int maxMessageSize = 65536 )
Initialized a new WebSocket client.
maxMessageSizeThe maximum message size to allow from the server, in bytes. Default 64 KiB.
public void AddSubProtocol( string protocol )
Add a sub-protocol to be negotiated during the WebSocket connection handshake.
public Task Connect( string websocketUri, CancellationToken ct = null )
Establishes a connection to an external WebSocket service.
websocketUriThe WebSocket URI to connect to. For example, "ws://hostname.local:1280/" for unencrypted WebSocket or "wss://hostname.local:1281/" for encrypted.ctA which allows the connection attempt to be aborted if necessary.- Returns A which completes when the connection is established, or throws if it failed to connect.
public ValueTask Send( string message )
Sends a text message to the WebSocket server.
messageThe message text to send. Must not be null.- Returns A which completes when the message was queued to be sent.
public ValueTask Send( byte[] data )
Sends a binary message to the WebSocket server.
Remarks: The and overloads allow sending subsections of byte arrays.
dataThe message data to send. Must not be null.- Returns A which completes when the message was queued to be sent.
public bool Equals( object obj )
😔 No documentation found.
public string ToString( )
😔 No documentation found.
public Type GetType( )
😔 No documentation found.
public ValueTask Send( Span<byte> data )
😔 No documentation found.
public ValueTask Send( ArraySegment<byte> data )
😔 No documentation found.
public Task Connect( string websocketUri, Dictionary<string,string> headers, CancellationToken ct = null )
😔 No documentation found.
public int GetHashCode( )
😔 No documentation found.
public void Dispose( )
😔 No documentation found.
public void add_OnMessageReceived( WebSocket.MessageReceivedHandler value )
😔 No documentation found.
public void remove_OnDisconnected( WebSocket.DisconnectedHandler value )
😔 No documentation found.
public void add_OnDisconnected( WebSocket.DisconnectedHandler value )
😔 No documentation found.
public void remove_OnDataReceived( WebSocket.DataReceivedHandler value )
😔 No documentation found.
public void remove_OnMessageReceived( WebSocket.MessageReceivedHandler value )
😔 No documentation found.
public void add_OnDataReceived( WebSocket.DataReceivedHandler value )
😔 No documentation found.