public sealed class WebSocketTransportA transport over WebSockets, for browsers and for anything behind a proxy.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
The medium already keeps most of the promises, which makes this the shortest of the three transports. A WebSocket is reliable, ordered, and message-framed, so there is no reliability layer here, no sequence numbers, no fragmentation and no reassembly — the things the UDP transport is mostly made of. What is left is a byte saying which channel a payload was sent on, a frame kind, and the timeouts.
The four channels collapse to one, and that is a real cost rather than a free win. Everything is delivered, in order, including the payloads whose channels say they need not be — which satisfies the contract, since Unreliable and Sequenced say a payload may be dropped rather than must. But the reason those channels exist is head-of-line blocking: a snapshot that supersedes itself thirty times a second should not wait behind a retransmission of one that is already stale, and over a single TCP stream it does. A browser client has no alternative and this is the right transport for it; a desktop client that could use UDP should.
The channel byte is still carried and still reported, so the layer above behaves identically and a game moved between transports does not change. It is the delivery guarantee that is stronger than asked for, not the vocabulary.
Fields and properties (6)
public const int MaxPayloadBytesThe largest payload, matching the in-process transport so a game can move between them.
public TransportCapabilities CapabilitiesWhat this transport can carry, and what it will not promise.
public TransportState ServerStateWhether the server half is listening.
public TransportState ClientStateWhether the client half is connected.
public Uri? ListeningOnWhere the server half is actually listening, once it has started.
public int ConnectionCountHow many clients are connected.
Methods (10)
public WebSocketTransport(IWebSocketFactory factory, WebSocketTransportOptions? options = null)Creates a transport.
public void StartServer()Starts listening. Where — a port, an address, a relay — was fixed when the transport was constructed, which is what keeps this interface free of anything socket-shaped.
public void StopServer()Stops listening and disconnects everyone, reporting ServerStopped to both sides. Does nothing if the server half is already stopped.
public void StartClient()Begins connecting. Completion is reported to OnConnected on a later Poll, or refusal to OnDisconnected — never inline, so the caller has one code path for "connected in a microsecond over loopback" and "connected in 90 ms over the Atlantic".
public void StopClient()Disconnects the client half, reporting Requested to this side and RemoteRequested to the server. Does nothing if the client half is already stopped.
public void Disconnect(ConnectionId connection)Closes one connection from the server side, reporting Requested here and Kicked there. Does nothing if the connection is not one of ours.
public void SendToClient(ConnectionId connection, ReadOnlySpan<byte> payload, Channel channel)Sends to one connected client. Does nothing if the connection is not ours.
public void SendToServer(ReadOnlySpan<byte> payload, Channel channel)Sends to the server. Does nothing if the client half is not connected.
public void Poll(TimeSpan elapsed, ITransportEvents events)Advances the transport by and reports everything that has happened since the last call, in the order it happened, to .
public void Dispose()Stops both halves and lets go of every socket.
Used by (4)
- CompositeTransportTestsVixen.Net.Transport.Composite.Tests
- RealWebSocketTestsVixen.Net.Transport.WebSocket.Tests
- SystemWebSocketChannelVixen.Net.Transport.WebSocket
- WebSocketTransportConformanceTestsVixen.Net.Transport.WebSocket.Tests