Table of Contents

Class WebsocketServer

Namespace
Alacrity.Internal
Assembly
Alacrity.Internal.dll

A simple Websocket Server implementation. Intended for internal usage by Alacrity, but written generically and can be used anywhere.

public class WebsocketServer
Inheritance
WebsocketServer
Inherited Members

Constructors

WebsocketServer(int, string)

Create a new WebsocketServer with a given bufferSize (for sending and receiving data). The securityString is used to create a "secret" that you can forward to the connecting client to ensure that not just anyone can connect.

public WebsocketServer(int bufferSize, string securityString)

Parameters

bufferSize int
securityString string

Methods

AddEventListener(Action<byte[], int>)

Add an event listener to receive binary data from connected clients. The action receives a byte buffer and a length. Any data in the buffer past the given length is undefined.

public void AddEventListener(Action<byte[], int> listener)

Parameters

listener Action<byte[], int>

AddEventListener(Action<string>)

Add an event listener to receive string data from connected clients.

public void AddEventListener(Action<string> listener)

Parameters

listener Action<string>

GetPort()

Get the port being listened on

public int GetPort()

Returns

int

RemoveEventListener(Action<byte[], int>)

Remove a previously added event listener.

public void RemoveEventListener(Action<byte[], int> listener)

Parameters

listener Action<byte[], int>

RemoveEventListener(Action<string>)

Remove a previously added event listener.

public void RemoveEventListener(Action<string> listener)

Parameters

listener Action<string>

SendToAll(byte[], int, int)

Send the data as a byte array to all connected clients.

public void SendToAll(byte[] data, int offset, int length)

Parameters

data byte[]
offset int
length int

SendToAll(string)

Send the message as a string to all connected clients.

public void SendToAll(string message)

Parameters

message string

Start()

Start the server

public void Start()

Stop()

Stop the server

public void Stop()

Events

OnClientConnect

public event WebsocketServer.ClientConnectOrDisconnectHandler OnClientConnect

Event Type

WebsocketServer.ClientConnectOrDisconnectHandler

OnClientDisconnect

public event WebsocketServer.ClientConnectOrDisconnectHandler OnClientDisconnect

Event Type

WebsocketServer.ClientConnectOrDisconnectHandler