C# Класс Bauglir.Ex.WebSocketServer

WebSocket server
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
connLock Object
fAddress System.Net.IPAddress
fConnections List
fIndex int
fIsRunning bool
fPort int
fSsl bool
fSslCertificate string
fTerminated bool
listener TcpListener

Открытые методы

Метод Описание
CloseAllConnection ( int aCloseCode, string aCloseReason ) : void

close all server connections

GetConnection ( int index ) : WebSocketServerConnection

return connection by its position in list

GetConnectionByIndex ( int index ) : WebSocketServerConnection

return connection by its position Index property

GetConnectionInstance ( TcpClient aClient, Bauglir.Ex.WebSocketHeaders aHeaders, string aHost, string aPort, string aResourceName, string aOrigin, string aCookie, string aVersion, string &aProtocol, string &aExtension, int &aHttpCode ) : WebSocketServerConnection

Function to create WebSocketServerConnection instance. Function should return null if connection should not be accepted or some non 101 HTTP result code (see below) if application implementation needs to use it's own inplementation of WebSocketServerConnection (based on WebSocketServerConnection class) application should create new WebSocketServer (based on this one) and override this method to return its own instance of connection based on either application logic or passed parameters All parameters, except for aClient and aHttpCode refers to properties in WebSocketConnection, check the documentation of WebSocketConnection Function does not have to set up phis variables to result object properties, it's done automatically by server after object is returned.

LockConnections ( ) : void

this function should be used when application needs to travers through connections function locks the connection list for removal from different thread, no connection will be removed until UnlockConnections is called UnlockConnections MUST be called after traversing

Start ( IPAddress aAddress, int aPort ) : bool

start server true server is able to listen and has started, false if error occures or server is already running

Stop ( ) : void

Stop server

UnlockConnections ( ) : void

this function should be used when application needs to travers through connections function unlocks the connection list for removal from different thread, function should be called after LockConnections is called

WebSocketServer ( ) : System

constructor function

Защищенные методы

Метод Описание
AddConnection ( TcpClient aClient, Stream aStream ) : WebSocketServerConnection

basic function to add WebSocket connection to list of connections

Execute ( ) : void

thread function this function actually waits for incomming connections and spawns new server threads

RemoveConnection ( WebSocketServerConnection aConnection ) : void
SafeRemoveConnection ( WebSocketServerConnection aConnection ) : void
httpCode ( int aCode ) : string

Описание методов

AddConnection() защищенный Метод

basic function to add WebSocket connection to list of connections
protected AddConnection ( TcpClient aClient, Stream aStream ) : WebSocketServerConnection
aClient System.Net.Sockets.TcpClient incomming connection
aStream Stream
Результат WebSocketServerConnection

CloseAllConnection() публичный Метод

close all server connections
public CloseAllConnection ( int aCloseCode, string aCloseReason ) : void
aCloseCode int WebSocketCloseCode constant reason
aCloseReason string textual data (max 123 bytes)
Результат void

Execute() защищенный Метод

thread function this function actually waits for incomming connections and spawns new server threads
protected Execute ( ) : void
Результат void

GetConnection() публичный Метод

return connection by its position in list
public GetConnection ( int index ) : WebSocketServerConnection
index int position in list
Результат WebSocketServerConnection

GetConnectionByIndex() публичный Метод

return connection by its position Index property
public GetConnectionByIndex ( int index ) : WebSocketServerConnection
index int connection's Index ptoperty
Результат WebSocketServerConnection

GetConnectionInstance() публичный Метод

Function to create WebSocketServerConnection instance. Function should return null if connection should not be accepted or some non 101 HTTP result code (see below) if application implementation needs to use it's own inplementation of WebSocketServerConnection (based on WebSocketServerConnection class) application should create new WebSocketServer (based on this one) and override this method to return its own instance of connection based on either application logic or passed parameters All parameters, except for aClient and aHttpCode refers to properties in WebSocketConnection, check the documentation of WebSocketConnection Function does not have to set up phis variables to result object properties, it's done automatically by server after object is returned.
public GetConnectionInstance ( TcpClient aClient, Bauglir.Ex.WebSocketHeaders aHeaders, string aHost, string aPort, string aResourceName, string aOrigin, string aCookie, string aVersion, string &aProtocol, string &aExtension, int &aHttpCode ) : WebSocketServerConnection
aClient System.Net.Sockets.TcpClient TcpClient requesting connection, client MUST NOT be closed by this function
aHeaders Bauglir.Ex.WebSocketHeaders
aHost string
aPort string
aResourceName string
aOrigin string If "-" passed, no origin was passed by client
aCookie string If "-" passed, no cookies was passed by client
aVersion string
aProtocol string In value is list of protocol requested by client ("-" if non requested). Out values should be list of protocol supported by server based on client request, if "-" is returned, no protocol will be negotitated
aExtension string In value is list of extensions requested by client ("-" if non requested). Out values should be list of extensions supported by server based on client request, if "-" is returned, no extensions will be negotitated
aHttpCode int HTTP result code to return, if other than 101 is returned, connection will be automatically closed. 101 is default value
Результат WebSocketServerConnection

LockConnections() публичный Метод

this function should be used when application needs to travers through connections function locks the connection list for removal from different thread, no connection will be removed until UnlockConnections is called UnlockConnections MUST be called after traversing
public LockConnections ( ) : void
Результат void

RemoveConnection() защищенный Метод

protected RemoveConnection ( WebSocketServerConnection aConnection ) : void
aConnection WebSocketServerConnection
Результат void

SafeRemoveConnection() защищенный Метод

protected SafeRemoveConnection ( WebSocketServerConnection aConnection ) : void
aConnection WebSocketServerConnection
Результат void

Start() публичный Метод

start server true server is able to listen and has started, false if error occures or server is already running
public Start ( IPAddress aAddress, int aPort ) : bool
aAddress System.Net.IPAddress
aPort int
Результат bool

Stop() публичный Метод

Stop server
public Stop ( ) : void
Результат void

UnlockConnections() публичный Метод

this function should be used when application needs to travers through connections function unlocks the connection list for removal from different thread, function should be called after LockConnections is called
public UnlockConnections ( ) : void
Результат void

WebSocketServer() публичный Метод

constructor function
public WebSocketServer ( ) : System
Результат System

httpCode() защищенный Метод

protected httpCode ( int aCode ) : string
aCode int
Результат string

Описание свойств

connLock защищенное свойство

protected Object connLock
Результат Object

fAddress защищенное свойство

protected IPAddress,System.Net fAddress
Результат System.Net.IPAddress

fConnections защищенное свойство

protected List fConnections
Результат List

fIndex защищенное свойство

protected int fIndex
Результат int

fIsRunning защищенное свойство

protected bool fIsRunning
Результат bool

fPort защищенное свойство

protected int fPort
Результат int

fSsl защищенное свойство

protected bool fSsl
Результат bool

fSslCertificate защищенное свойство

protected string fSslCertificate
Результат string

fTerminated защищенное свойство

protected bool fTerminated
Результат bool

listener защищенное свойство

protected TcpListener listener
Результат TcpListener