Server
Namespace: TagBites.Net
Assembly: TagBites.Net.dll
TCP server which allows to send objects messages and execute remote methods. This class is thread safe.
public class Server : System.IDisposable
Constructors
Server(string, int)
Initializes a new instance of the TagBites.Net.Server class.
public void Server(string host, int port)
Result Type: void
Parameters
Type | Name | |
---|---|---|
string | host | Address on which server is listening for clients. |
int | port | Port on which server is listening for clients. |
Server(string, int, NetworkConfig)
Initializes a new instance of the TagBites.Net.Server class.
public void Server(string host, int port, NetworkConfig config)
Result Type: void
Parameters
Type | Name | |
---|---|---|
string | host | Address on which server is listening for clients. |
int | port | Port on which server is listening for clients. |
NetworkConfig | config | Network configuration. |
Server(string, int, X509Certificate)
Initializes a new instance of the TagBites.Net.Server class.
public void Server(string host, int port, X509Certificate certificate)
Result Type: void
Parameters
Type | Name | |
---|---|---|
string | host | Address on which server is listening for clients. |
int | port | Port on which server is listening for clients. |
X509Certificate | certificate | Certificate used to secure connection (ssl). |
Server(string, int, X509Certificate, NetworkConfig)
Initializes a new instance of the TagBites.Net.Server class.
public void Server(string host, int port, X509Certificate certificate, NetworkConfig config)
Result Type: void
Parameters
Type | Name | |
---|---|---|
string | host | Address on which server is listening for clients. |
int | port | Port on which server is listening for clients. |
X509Certificate | certificate | Certificate used to secure connection (ssl). |
NetworkConfig | config | Network configuration. |
Server(IPEndPoint)
Initializes a new instance of the TagBites.Net.Server class.
public void Server(IPEndPoint address)
Result Type: void
Parameters
Type | Name | |
---|---|---|
IPEndPoint | address | Address on which server is listening for clients. |
Server(IPEndPoint, NetworkConfig)
Initializes a new instance of the TagBites.Net.Server class.
public void Server(IPEndPoint address, NetworkConfig config)
Result Type: void
Parameters
Type | Name | |
---|---|---|
IPEndPoint | address | Address on which server is listening for clients. |
NetworkConfig | config | Network configuration. |
Server(IPEndPoint, X509Certificate)
Initializes a new instance of the TagBites.Net.Server class.
public void Server(IPEndPoint address, X509Certificate certificate)
Result Type: void
Parameters
Type | Name | |
---|---|---|
IPEndPoint | address | Address on which server is listening for clients. |
X509Certificate | certificate | Certificate used to secure connection (ssl). |
Server(IPEndPoint, X509Certificate, NetworkConfig)
Initializes a new instance of the TagBites.Net.Server class.
public void Server(IPEndPoint address, X509Certificate certificate, NetworkConfig config)
Result Type: void
Parameters
Type | Name | |
---|---|---|
IPEndPoint | address | Address on which server is listening for clients. |
X509Certificate | certificate | Certificate used to secure connection (ssl). |
NetworkConfig | config | Network configuration. |
Properties
DisconnectClientsOnDispose
Gets or sets a value indicating whether to dispose connected clients when server is disposing.
public bool DisconnectClientsOnDispose { get; set; }
Result Type: bool
IsDisposed
Gets a value indicating whether object already disposed or not.
public bool IsDisposed { get; }
Result Type: bool
Listening
Gets or sets a value indicating whether server is listening for clients. Setting <c>true</c> starts background thread.
public bool Listening { get; set; }
Result Type: bool
LocalEndpoint
Gets an address on which server is listening for clients.
public IPEndPoint LocalEndpoint { get; }
Result Type: IPEndPoint
Methods
Dispose()
public void Dispose()
Result Type: void
Dispose(bool)
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
protected void Dispose(bool disposing)
Result Type: void
Parameters
Type | Name | |
---|---|---|
bool | disposing |
GetClient(object)
Returns connected client with the given ``.
public ServerClient GetClient(object identity)
Result Type: ServerClient
Parameters
Type | Name | |
---|---|---|
object | identity | Client identity. |
GetClients()
Returns connected clients.
public ServerClient[] GetClients()
Result Type: ServerClient[]
OnClientControllerResolve(ServerClient, NetworkConnectionControllerResolveEventArgs)
Invokes TagBites.Net.Server.ControllerResolve event.
protected internal void OnClientControllerResolve(ServerClient client, NetworkConnectionControllerResolveEventArgs e)
Result Type: void
Parameters
Type | Name | |
---|---|---|
ServerClient | client | Client which raised the event. |
NetworkConnectionControllerResolveEventArgs | e | Client event argument. |
OnClientDisconnected(ServerClient, NetworkConnectionClosedEventArgs)
Removes client form the client list and invokes TagBites.Net.Server.ClientDisconnected event.
protected internal void OnClientDisconnected(ServerClient client, NetworkConnectionClosedEventArgs e)
Result Type: void
Parameters
Type | Name | |
---|---|---|
ServerClient | client | Client which raised the event. |
NetworkConnectionClosedEventArgs | e | Client event argument. |
OnClientReceived(ServerClient, NetworkConnectionMessageEventArgs)
Invokes TagBites.Net.Server.Received event.
protected internal void OnClientReceived(ServerClient client, NetworkConnectionMessageEventArgs e)
Result Type: void
Parameters
Type | Name | |
---|---|---|
ServerClient | client | Client which raised the event. |
NetworkConnectionMessageEventArgs | e | Client event argument. |
OnClientReceivedError(ServerClient, NetworkConnectionMessageErrorEventArgs)
Invokes TagBites.Net.Server.ReceivedError event.
protected internal void OnClientReceivedError(ServerClient client, NetworkConnectionMessageErrorEventArgs e)
Result Type: void
Parameters
Type | Name | |
---|---|---|
ServerClient | client | Client which raised the event. |
NetworkConnectionMessageErrorEventArgs | e | Client event argument. |
SendToAllAsync(object)
Sends message to all clients.
public Task SendToAllAsync(object message)
Result Type: Task
Parameters
Type | Name | |
---|---|---|
object | message | Message to send. |
SendToAllAsync(object, ServerClient)
Sends message to all clients except given one (``).
public Task SendToAllAsync(object message, ServerClient exceptClient)
Result Type: Task
Parameters
Type | Name | |
---|---|---|
object | message | Message to send. |
ServerClient | exceptClient | Client to whom do not send message. |
Use<TControllerInterface, TController>()
Register local controller.
public void Use()
Result Type: void
Use<TControllerInterface, TController>(Func<ServerClient, TController>)
Register local controller.
public void Use(Func<ServerClient, TController> controllerProvider)
Result Type: void
Parameters
Type | Name | |
---|---|---|
Func<ServerClient,TController> | controllerProvider | Controller instance. |
Events
ClientAuthenticate
Occurs right after tcp connection has been established, but before TagBites.Net.Server.ClientConnected event. It allows to authenticate client and assign identity.
public EventHandler<ServerClientAuthenticateEventArgs> ClientAuthenticate
Result Type: EventHandler<ServerClientAuthenticateEventArgs>
ClientConnected
Occurs after the connection is established and client is successfully authenticated.
public EventHandler<ServerClientEventArgs> ClientConnected
Result Type: EventHandler<ServerClientEventArgs>
ClientConnectingError
Occurs when an exception is thrown while accepting tcp client, or during authentication procedure, or during TagBites.Net.Server.ClientConnected event.
public EventHandler<ServerClientConnectExceptionEventArgs> ClientConnectingError
Result Type: EventHandler<ServerClientConnectExceptionEventArgs>
ClientDisconnected
Occurs when client disconnects form the server.
public EventHandler<ServerClientEventArgs> ClientDisconnected
Result Type: EventHandler<ServerClientEventArgs>
ControllerResolve
Occurs when client requests access to controller for the first time.
public EventHandler<ServerClientControllerResolveEventArgs> ControllerResolve
Result Type: EventHandler<ServerClientControllerResolveEventArgs>
Received
Occurs when client sends a message.
public EventHandler<ServerClientMessageEventArgs> Received
Result Type: EventHandler<ServerClientMessageEventArgs>
ReceivedError
Occurs when server was unable to receive client message (eg. deserialization error).
public EventHandler<ServerClientMessageErrorEventArgs> ReceivedError
Result Type: EventHandler<ServerClientMessageErrorEventArgs>