Skip to content

Class WebSocketConnection

A WebSocket byte stream: each message in is a run of bytes for the terminal, and each run of bytes out is one binary message. It runs in a WebGL player, where DarkEffekt.Terminal.TcpConnection cannot, and suits a relay in front of a pty or a serial port. Connect returns at once; a connect that fails arrives through Closed, and bytes sent before the connect completes go out once it does.

Declaration
public class WebSocketConnection : ITerminalConnection

Derived:
DarkEffekt.Terminal.TtydConnection

Implements:
DarkEffekt.Terminal.ITerminalConnection

The address, starting with ws:// or wss://.

Declaration
public string Url { get; }

The subprotocols to offer the server, in order of preference. Set before Connect.

Declaration
public IReadOnlyList<string> Subprotocols { get; set; }
Declaration
public bool IsConnected { get; }

Starts connecting and returns at once; Connected or Closed reports the outcome.

Declaration
public void Connect()

The socket is open. Runs before anything queued goes out and before Connected, so a message sent from here with SendRaw is the first the server reads.

Declaration
protected virtual void OnConnected()

Processes one message from the server. The base class raises DataReceived with it.

Declaration
protected virtual void HandleMessage(byte[] data)
Type Name
System.Byte[] data
Declaration
protected void RaiseDataReceived(byte[] data)
Type Name
System.Byte[] data

Queues bytes for the far end. Never blocks on the network.

Declaration
public virtual void Send(byte[] data, int offset, int count)
Type Name
System.Byte[] data
System.Int32 offset
System.Int32 count

Queues one message for the server as it is. The array must not change afterward.

Declaration
protected void SendRaw(byte[] data)
Type Name
System.Byte[] data

The terminal grid changed size. Connections that can pass this on do.

Declaration
public virtual void NotifyResize(int cols, int rows)
Type Name
System.Int32 cols
System.Int32 rows

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public void Dispose()

The stream is open and data can flow.

Declaration
public event Action Connected

System.Action

Declaration
public event Action<byte[]> DataReceived

System.Action<System.Byte[]>

Declaration
public event Action<CloseReason> Closed

System.Action<DarkEffekt.Terminal.CloseReason>