reckfellENGINE

WebSocketPeer

A manually polled WebSocket connection with message boundaries.

On this page
class WebSocketPeerReckfellSharpInherits PacketPeer

ConnectToUrl begins a handshake; AcceptStream accepts a suitable TCP/TLS stream. Continue Poll and inspect GetReadyState: startup Error.Ok does not mean Open. Read through GetPacket/GetPacketError and distinguish text/bytes with WasStringPacket.

Close begins closing; continue polling until Closed or deadline. Raw WebSocket does not synchronize Entity instances or automatically provide SceneMultiplayer RPC. WSS requires verified TLS options and a suitable server.

Practical guide.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors1

WebSocketPeerConstructor
# WebSocketPeer
C#
public WebSocketPeer();

Properties6

HandshakeHeadersProperty
# HandshakeHeaders
C#
public string[] HandshakeHeaders { get; set; }

The extra HTTP headers to be sent during the WebSocket handshake. Note: Not supported in Web exports due to browser restrictions.

HeartbeatIntervalProperty
# HeartbeatInterval
C#
public double HeartbeatInterval { get; set; }

The interval (in seconds) at which the peer will automatically send WebSocket "ping" control frames. When set to 0, no "ping" control frames will be sent. Note: Has no effect in Web exports due to browser restrictions.

InboundBufferSizeProperty
# InboundBufferSize
C#
public int InboundBufferSize { get; set; }

The size of the input buffer in bytes (roughly the maximum amount of memory that will be allocated for the inbound packets).

MaxQueuedPacketsProperty
# MaxQueuedPackets
C#
public int MaxQueuedPackets { get; set; }

The maximum amount of packets that will be allowed in the queues (both inbound and outbound).

OutboundBufferSizeProperty
# OutboundBufferSize
C#
public int OutboundBufferSize { get; set; }

The size of the input buffer in bytes (roughly the maximum amount of memory that will be allocated for the outbound packets).

SupportedProtocolsProperty
# SupportedProtocols
C#
public string[] SupportedProtocols { get; set; }

Proposed/accepted WebSocket subprotocols. A subprotocol name does not automatically define your game message format.

Methods31

AcceptStreamError
# AcceptStream
C#
public Error AcceptStream(StreamPeer stream);

Begins a server WebSocket handshake over a suitable connected stream. Establish TLS first for WSS; ordinary TCP does not add encryption.

Parameters
NameTypeDefault
streamStreamPeer—
Returns Error
Closevoid
# Close
C#
public void Close(int code = 1000, string reason = "");

Begins closing with a code/reason. Continue Poll until Closed; owner removal can interrupt the closing handshake.

Parameters
NameTypeDefault
codeint1000
reasonstring""
ConnectToUrlError
# ConnectToUrl
C#
public Error ConnectToUrl(string url, TlsOptions tlsClientOptions = null);

Begins WS/WSS connection. After Error.Ok continue Poll until Open; use verified TLS options for WSS.

Parameters
NameTypeDefault
urlstring—
tlsClientOptionsTlsOptionsnull
Returns Error
GetCloseCodeint
# GetCloseCode
C#
public int GetCloseCode();

Close code when available. Abrupt loss or failed handshake need not have normal code 1000; interpret with state/diagnostics.

Returns int
GetCloseReasonstring
# GetCloseReason
C#
public string GetCloseReason();

Returns the received WebSocket close frame status reason string. Only call this method when WebSocketPeer.GetReadyState returns WebSocketPeer.State.Closed.

Returns string
GetConnectedHoststring
# GetConnectedHost
C#
public string GetConnectedHost();

Returns the IP address of the connected peer. Note: Not available in the Web export.

Returns string
GetConnectedPortushort
# GetConnectedPort
C#
public ushort GetConnectedPort();

Returns the remote port of the connected peer. Note: Not available in the Web export.

Returns ushort
GetCurrentOutboundBufferedAmountint
# GetCurrentOutboundBufferedAmount
C#
public int GetCurrentOutboundBufferedAmount();

Returns the current amount of data in the outbound websocket buffer. Note: Web exports use WebSocket.bufferedAmount, while other platforms use an internal buffer.

Returns int
GetHandshakeHeadersstring[]
# GetHandshakeHeaders
C#
public string[] GetHandshakeHeaders();
Returns string[]
GetHeartbeatIntervaldouble
# GetHeartbeatInterval
C#
public double GetHeartbeatInterval();
Returns double
GetInboundBufferSizeint
# GetInboundBufferSize
C#
public int GetInboundBufferSize();
Returns int
GetMaxQueuedPacketsint
# GetMaxQueuedPackets
C#
public int GetMaxQueuedPackets();
Returns int
GetOutboundBufferSizeint
# GetOutboundBufferSize
C#
public int GetOutboundBufferSize();
Returns int
GetReadyStateWebSocketPeer.State
# GetReadyState
C#
public WebSocketPeer.State GetReadyState();

Returns the ready state of the connection.

Returns WebSocketPeer.State
GetRequestedUrlstring
# GetRequestedUrl
C#
public string GetRequestedUrl();

Returns the URL requested by this peer. The URL is derived from the url passed to WebSocketPeer.ConnectToUrl or from the HTTP headers when acting as server (i.e. when using WebSocketPeer.AcceptStream).

Returns string
GetSelectedProtocolstring
# GetSelectedProtocol
C#
public string GetSelectedProtocol();

Returns the selected WebSocket sub-protocol for this connection or an empty string if the sub-protocol has not been selected yet.

Returns string
GetSupportedProtocolsstring[]
# GetSupportedProtocols
C#
public string[] GetSupportedProtocols();
Returns string[]
Pollvoid
# Poll
C#
public void Poll();

Advances handshake, incoming data and closing. Continue in Closing until Closed or your deadline.

Send2 overloads
# Send · 1/2
C#
public Error Send(byte[] message, WebSocketPeer.WriteMode writeMode = WebSocketPeer.WriteMode.Binary);

Sends bytes with the selected WriteMode. Binary payload and UTF-8 text are distinct message types; agree the application format separately.

Parameters
NameTypeDefault
messagebyte[]—
writeModeWebSocketPeer.WriteModeWebSocketPeer.WriteMode.Binary
Returns Error
# Send · 2/2
C#
public Error Send(ReadOnlySpan<byte> message, WebSocketPeer.WriteMode writeMode);

Sends bytes with the selected WriteMode. Binary payload and UTF-8 text are distinct message types; agree the application format separately.

Parameters
NameTypeDefault
messageReadOnlySpan<byte>—
writeModeWebSocketPeer.WriteMode—
Returns Error
SendTextError
# SendText
C#
public Error SendText(string message);

Sends UTF-8 text on an open connection. Check Error and an application byte limit; successful sending does not establish server-side action completion.

Parameters
NameTypeDefault
messagestring—
Returns Error
SetHandshakeHeaders2 overloads
# SetHandshakeHeaders · 1/2
C#
public void SetHandshakeHeaders(ReadOnlySpan<string> protocols);
Parameters
NameTypeDefault
protocolsReadOnlySpan<string>—
# SetHandshakeHeaders · 2/2
C#
public void SetHandshakeHeaders(string[] protocols);
Parameters
NameTypeDefault
protocolsstring[]—
SetHeartbeatIntervalvoid
# SetHeartbeatInterval
C#
public void SetHeartbeatInterval(double interval);
Parameters
NameTypeDefault
intervaldouble—
SetInboundBufferSizevoid
# SetInboundBufferSize
C#
public void SetInboundBufferSize(int bufferSize);
Parameters
NameTypeDefault
bufferSizeint—
SetMaxQueuedPacketsvoid
# SetMaxQueuedPackets
C#
public void SetMaxQueuedPackets(int bufferSize);
Parameters
NameTypeDefault
bufferSizeint—
SetNoDelayvoid
# SetNoDelay
C#
public void SetNoDelay(bool enabled);

Disable Nagle's algorithm on the underlying TCP socket (default). See StreamPeerTcp.SetNoDelay for more information. Note: Not available in the Web export.

Parameters
NameTypeDefault
enabledbool—
SetOutboundBufferSizevoid
# SetOutboundBufferSize
C#
public void SetOutboundBufferSize(int bufferSize);
Parameters
NameTypeDefault
bufferSizeint—
SetSupportedProtocols2 overloads
# SetSupportedProtocols · 1/2
C#
public void SetSupportedProtocols(ReadOnlySpan<string> protocols);
Parameters
NameTypeDefault
protocolsReadOnlySpan<string>—
# SetSupportedProtocols · 2/2
C#
public void SetSupportedProtocols(string[] protocols);
Parameters
NameTypeDefault
protocolsstring[]—
WasStringPacketbool
# WasStringPacket
C#
public bool WasStringPacket();

Reports the last received packet type. Inspect after GetPacket; it does not describe every future message on the connection.

Returns bool

WebSocketPeer.State

ValueDescription
Closed = 3

The connection is closed or couldn't be opened.

Closing = 2

The connection is in the process of closing. This means a close request has been sent to the remote peer but confirmation has not been received.

Connecting = 0

Socket has been created. The connection is not yet open.

Open = 1

The connection is open and ready to communicate.

WebSocketPeer.WriteMode

ValueDescription
Binary = 1

Specifies that WebSockets messages should be transferred as binary payload (any byte combination is allowed).

Text = 0

Specifies that WebSockets messages should be transferred as text payload (only valid UTF-8 is allowed).

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.