Class WebsocketServer
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
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
AddEventListener(Action<string>)
Add an event listener to receive string data from connected clients.
public void AddEventListener(Action<string> listener)
Parameters
GetPort()
Get the port being listened on
public int GetPort()
Returns
RemoveEventListener(Action<byte[], int>)
Remove a previously added event listener.
public void RemoveEventListener(Action<byte[], int> listener)
Parameters
RemoveEventListener(Action<string>)
Remove a previously added event listener.
public void RemoveEventListener(Action<string> listener)
Parameters
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
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
OnClientDisconnect
public event WebsocketServer.ClientConnectOrDisconnectHandler OnClientDisconnect