Server
Namespace: TagBites.Net
Assembly: TagBites.Net.dll
Product: TagBites.Net v. 1.0.3
TCP server which allows to send objects messages and execute remote methods. This class is thread safe.
public class Server : System.IDisposableInheritance: object → Server
Constructors
Section titled “Constructors”Server(string, int)
Section titled “Server(string, int)”Initializes a new instance of the Server class.
public Server(string host, int port)Parameters
Section titled “Parameters”hoststring
Address on which server is listening for clients.portint
Port on which server is listening for clients.
Server(string, int, NetworkConfig)
Section titled “Server(string, int, NetworkConfig)”Initializes a new instance of the Server class.
public Server(string host, int port, NetworkConfig config)Parameters
Section titled “Parameters”hoststring
Address on which server is listening for clients.portint
Port on which server is listening for clients.configNetworkConfig
Network configuration.
Server(string, int, X509Certificate)
Section titled “Server(string, int, X509Certificate)”Initializes a new instance of the Server class.
public Server(string host, int port, X509Certificate certificate)Parameters
Section titled “Parameters”hoststring
Address on which server is listening for clients.portint
Port on which server is listening for clients.certificateX509Certificate
Certificate used to secure connection (ssl).
Server(string, int, X509Certificate, NetworkConfig)
Section titled “Server(string, int, X509Certificate, NetworkConfig)”Initializes a new instance of the Server class.
public Server(string host, int port, X509Certificate certificate, NetworkConfig config)Parameters
Section titled “Parameters”hoststring
Address on which server is listening for clients.portint
Port on which server is listening for clients.certificateX509Certificate
Certificate used to secure connection (ssl).configNetworkConfig
Network configuration.
Server(IPEndPoint)
Section titled “Server(IPEndPoint)”Initializes a new instance of the Server class.
public Server(IPEndPoint address)Parameters
Section titled “Parameters”addressIPEndPoint
Address on which server is listening for clients.
Server(IPEndPoint, NetworkConfig)
Section titled “Server(IPEndPoint, NetworkConfig)”Initializes a new instance of the Server class.
public Server(IPEndPoint address, NetworkConfig config)Parameters
Section titled “Parameters”addressIPEndPoint
Address on which server is listening for clients.configNetworkConfig
Network configuration.
Server(IPEndPoint, X509Certificate)
Section titled “Server(IPEndPoint, X509Certificate)”Initializes a new instance of the Server class.
public Server(IPEndPoint address, X509Certificate certificate)Parameters
Section titled “Parameters”addressIPEndPoint
Address on which server is listening for clients.certificateX509Certificate
Certificate used to secure connection (ssl).
Server(IPEndPoint, X509Certificate, NetworkConfig)
Section titled “Server(IPEndPoint, X509Certificate, NetworkConfig)”Initializes a new instance of the Server class.
public Server(IPEndPoint address, X509Certificate certificate, NetworkConfig config)Parameters
Section titled “Parameters”addressIPEndPoint
Address on which server is listening for clients.certificateX509Certificate
Certificate used to secure connection (ssl).configNetworkConfig
Network configuration.
Properties
Section titled “Properties”DisconnectClientsOnDispose
Section titled “DisconnectClientsOnDispose”Gets or sets a value indicating whether to dispose connected clients when server is disposing.
public bool DisconnectClientsOnDispose { get; set; }Property Value
Section titled “Property Value”IsDisposed
Section titled “IsDisposed”Gets a value indicating whether the object has been disposed.
public bool IsDisposed { get; }Property Value
Section titled “Property Value”Listening
Section titled “Listening”Gets or sets a value indicating whether server is listening for clients. Setting true starts accepting clients on a background thread. The listener itself starts before the setter returns, so a bind error is thrown to the caller.
public bool Listening { get; set; }Property Value
Section titled “Property Value”LocalEndpoint
Section titled “LocalEndpoint”Gets an address on which server is listening for clients.
public IPEndPoint LocalEndpoint { get; }Property Value
Section titled “Property Value”Methods
Section titled “Methods”Dispose()
Section titled “Dispose()”public virtual void Dispose()Dispose(bool)
Section titled “Dispose(bool)”Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
protected virtual void Dispose(bool disposing)Parameters
Section titled “Parameters”disposingbool
GetClient(object)
Section titled “GetClient(object)”Returns connected client with the given identity.
public ServerClient GetClient(object identity)Parameters
Section titled “Parameters”identityobject
Client identity.
Returns
Section titled “Returns”GetClients()
Section titled “GetClients()”Returns connected clients.
public ServerClient[] GetClients()Returns
Section titled “Returns”ListenAsync()
Section titled “ListenAsync()”Accepts clients on the calling task, until Listening is set to false or the server is disposed. Returns immediately when the server is already listening.
public Task ListenAsync()Returns
Section titled “Returns”Remarks
Section titled “Remarks”Setting Listening to true does the same on a background thread.
OnClientControllerResolve(ServerClient, NetworkConnectionControllerResolveEventArgs)
Section titled “OnClientControllerResolve(ServerClient, NetworkConnectionControllerResolveEventArgs)”Invokes ControllerResolve event.
protected internal virtual void OnClientControllerResolve(ServerClient client, NetworkConnectionControllerResolveEventArgs e)Parameters
Section titled “Parameters”clientServerClient
Client which raised the event.eNetworkConnectionControllerResolveEventArgs
Client event argument.
OnClientDisconnected(ServerClient, NetworkConnectionClosedEventArgs)
Section titled “OnClientDisconnected(ServerClient, NetworkConnectionClosedEventArgs)”Removes client form the client list and invokes ClientDisconnected event.
protected internal virtual void OnClientDisconnected(ServerClient client, NetworkConnectionClosedEventArgs e)Parameters
Section titled “Parameters”clientServerClient
Client which raised the event.eNetworkConnectionClosedEventArgs
Client event argument.
OnClientReceived(ServerClient, NetworkConnectionMessageEventArgs)
Section titled “OnClientReceived(ServerClient, NetworkConnectionMessageEventArgs)”Invokes Received event.
protected internal virtual void OnClientReceived(ServerClient client, NetworkConnectionMessageEventArgs e)Parameters
Section titled “Parameters”clientServerClient
Client which raised the event.eNetworkConnectionMessageEventArgs
Client event argument.
OnClientReceivedError(ServerClient, NetworkConnectionMessageErrorEventArgs)
Section titled “OnClientReceivedError(ServerClient, NetworkConnectionMessageErrorEventArgs)”Invokes ReceivedError event.
protected internal virtual void OnClientReceivedError(ServerClient client, NetworkConnectionMessageErrorEventArgs e)Parameters
Section titled “Parameters”clientServerClient
Client which raised the event.eNetworkConnectionMessageErrorEventArgs
Client event argument.
SendToAllAsync(object)
Section titled “SendToAllAsync(object)”Sends message to all clients.
public Task SendToAllAsync(object message)Parameters
Section titled “Parameters”messageobject
Message to send.
Returns
Section titled “Returns”SendToAllAsync(object, ServerClient)
Section titled “SendToAllAsync(object, ServerClient)”Sends message to all clients except given one (exceptClient).
public Task SendToAllAsync(object message, ServerClient exceptClient)Parameters
Section titled “Parameters”messageobject
Message to send.exceptClientServerClient
Client to whom do not send message.
Returns
Section titled “Returns”Use<TControllerInterface, TController>()
Section titled “Use<TControllerInterface, TController>()”Registers a local controller. The instance is created on first use.
public void Use()Type Parameters
Section titled “Type Parameters”TControllerInterface
Controller interface.TController
Controller type.
Use<TControllerInterface, TController>(Func<ServerClient, TController>)
Section titled “Use<TControllerInterface, TController>(Func<ServerClient, TController>)”Registers a local controller created separately for each client.
public void Use(Func<ServerClient, TController> controllerProvider)Type Parameters
Section titled “Type Parameters”TControllerInterface
Controller interface.TController
Controller type.
Parameters
Section titled “Parameters”controllerProviderFunc<ServerClient, TController>
Function which creates the controller for a client.
Events
Section titled “Events”ClientAuthenticate
Section titled “ClientAuthenticate”Occurs right after tcp connection has been established, but before ClientConnected event. It allows to authenticate client and assign identity.
public EventHandler<ServerClientAuthenticateEventArgs> ClientAuthenticateEvent Type
Section titled “Event Type”EventHandler<ServerClientAuthenticateEventArgs>
ClientConnected
Section titled “ClientConnected”Occurs after the connection is established and client is successfully authenticated.
public EventHandler<ServerClientEventArgs> ClientConnectedEvent Type
Section titled “Event Type”EventHandler<ServerClientEventArgs>
ClientConnectingError
Section titled “ClientConnectingError”Occurs when an exception is thrown while accepting tcp client, or during authentication procedure, or during ClientConnected event.
public EventHandler<ServerClientConnectExceptionEventArgs> ClientConnectingErrorEvent Type
Section titled “Event Type”EventHandler<ServerClientConnectExceptionEventArgs>
ClientDisconnected
Section titled “ClientDisconnected”Occurs when client disconnects form the server.
public EventHandler<ServerClientEventArgs> ClientDisconnectedEvent Type
Section titled “Event Type”EventHandler<ServerClientEventArgs>
ControllerResolve
Section titled “ControllerResolve”Occurs when client requests access to controller for the first time.
public EventHandler<ServerClientControllerResolveEventArgs> ControllerResolveEvent Type
Section titled “Event Type”EventHandler<ServerClientControllerResolveEventArgs>
Received
Section titled “Received”Occurs when client sends a message.
public EventHandler<ServerClientMessageEventArgs> ReceivedEvent Type
Section titled “Event Type”EventHandler<ServerClientMessageEventArgs>
ReceivedError
Section titled “ReceivedError”Occurs when server was unable to receive client message (eg. deserialization error).
public EventHandler<ServerClientMessageErrorEventArgs> ReceivedError