Skip to content
Auto
Products

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.IDisposable

Inheritance: object → Server

Initializes a new instance of the Server class.

public Server(string host, int port)
  • host string
    Address on which server is listening for clients.
  • port int
    Port on which server is listening for clients.

Initializes a new instance of the Server class.

public Server(string host, int port, NetworkConfig config)
  • host string
    Address on which server is listening for clients.
  • port int
    Port on which server is listening for clients.
  • config NetworkConfig
    Network configuration.

Initializes a new instance of the Server class.

public Server(string host, int port, X509Certificate certificate)
  • host string
    Address on which server is listening for clients.
  • port int
    Port on which server is listening for clients.
  • certificate X509Certificate
    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)
  • host string
    Address on which server is listening for clients.
  • port int
    Port on which server is listening for clients.
  • certificate X509Certificate
    Certificate used to secure connection (ssl).
  • config NetworkConfig
    Network configuration.

Initializes a new instance of the Server class.

public Server(IPEndPoint address)
  • address IPEndPoint
    Address on which server is listening for clients.

Initializes a new instance of the Server class.

public Server(IPEndPoint address, NetworkConfig config)

Initializes a new instance of the Server class.

public Server(IPEndPoint address, X509Certificate certificate)
  • address IPEndPoint
    Address on which server is listening for clients.
  • certificate X509Certificate
    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)

Gets or sets a value indicating whether to dispose connected clients when server is disposing.

public bool DisconnectClientsOnDispose { get; set; }

bool

Gets a value indicating whether the object has been disposed.

public bool IsDisposed { get; }

bool

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; }

bool

Gets an address on which server is listening for clients.

public IPEndPoint LocalEndpoint { get; }

IPEndPoint

public virtual void Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

protected virtual void Dispose(bool disposing)

Returns connected client with the given identity.

public ServerClient GetClient(object identity)
  • identity object
    Client identity.

ServerClient

Returns connected clients.

public ServerClient[] GetClients()

ServerClient[]

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()

Task

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)

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)

OnClientReceived(ServerClient, NetworkConnectionMessageEventArgs)

Section titled “OnClientReceived(ServerClient, NetworkConnectionMessageEventArgs)”

Invokes Received event.

protected internal virtual void OnClientReceived(ServerClient client, NetworkConnectionMessageEventArgs e)

OnClientReceivedError(ServerClient, NetworkConnectionMessageErrorEventArgs)

Section titled “OnClientReceivedError(ServerClient, NetworkConnectionMessageErrorEventArgs)”

Invokes ReceivedError event.

protected internal virtual void OnClientReceivedError(ServerClient client, NetworkConnectionMessageErrorEventArgs e)

Sends message to all clients.

public Task SendToAllAsync(object message)
  • message object
    Message to send.

Task

Sends message to all clients except given one (exceptClient).

public Task SendToAllAsync(object message, ServerClient exceptClient)
  • message object
    Message to send.
  • exceptClient ServerClient
    Client to whom do not send message.

Task

Registers a local controller. The instance is created on first use.

public void Use()
  • 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)
  • TControllerInterface
    Controller interface.
  • TController
    Controller type.
  • controllerProvider Func<ServerClient, TController>
    Function which creates the controller for a client.

Occurs right after tcp connection has been established, but before ClientConnected event. It allows to authenticate client and assign identity.

public EventHandler<ServerClientAuthenticateEventArgs> ClientAuthenticate

EventHandler<ServerClientAuthenticateEventArgs>

Occurs after the connection is established and client is successfully authenticated.

public EventHandler<ServerClientEventArgs> ClientConnected

EventHandler<ServerClientEventArgs>

Occurs when an exception is thrown while accepting tcp client, or during authentication procedure, or during ClientConnected event.

public EventHandler<ServerClientConnectExceptionEventArgs> ClientConnectingError

EventHandler<ServerClientConnectExceptionEventArgs>

Occurs when client disconnects form the server.

public EventHandler<ServerClientEventArgs> ClientDisconnected

EventHandler<ServerClientEventArgs>

Occurs when client requests access to controller for the first time.

public EventHandler<ServerClientControllerResolveEventArgs> ControllerResolve

EventHandler<ServerClientControllerResolveEventArgs>

Occurs when client sends a message.

public EventHandler<ServerClientMessageEventArgs> Received

EventHandler<ServerClientMessageEventArgs>

Occurs when server was unable to receive client message (eg. deserialization error).

public EventHandler<ServerClientMessageErrorEventArgs> ReceivedError

EventHandler<ServerClientMessageErrorEventArgs>