Class NetworkServer
The network server.
Implements
Inherited Members
Namespace: Evergine.Networking.Connection
Assembly: Evergine.Networking.dll
Syntax
public class NetworkServer : INetworkServer
Constructors
NetworkServer(string, int, float, float, string)
Initializes a new instance of the NetworkServer class.
Declaration
public NetworkServer(string applicationIdentifier, int port, float pingInterval, float connectionTimeout, string serverName = null)
Parameters
Type | Name | Description |
---|---|---|
string | applicationIdentifier | The application identifier. |
int | port | The port. |
float | pingInterval | Ping interval in seconds. |
float | connectionTimeout | Connection timeout in seconds. |
string | serverName | The server name. It is sent in every discovery response. |
Methods
CreateMessage(MessageType)
Creates a new outgoing message.
Declaration
public OutgoingMessage CreateMessage(MessageType type = MessageType.Data)
Parameters
Type | Name | Description |
---|---|---|
MessageType | type | The type. |
Returns
Type | Description |
---|---|
OutgoingMessage | The created outgoing message. |
OnClientConnected(NetworkEndpoint, IncomingMessage)
Called when [client connected].
Declaration
protected virtual void OnClientConnected(NetworkEndpoint client, IncomingMessage hailMessage)
Parameters
Type | Name | Description |
---|---|---|
NetworkEndpoint | client | The client endpoint. |
IncomingMessage | hailMessage | The hail message received from the client. |
OnClientDisconnected(NetworkEndpoint)
Called when [client disconnected].
Declaration
protected virtual void OnClientDisconnected(NetworkEndpoint client)
Parameters
Type | Name | Description |
---|---|---|
NetworkEndpoint | client | The client endpoint. |
OnMessageReceived(NetworkEndpoint, IncomingMessage)
Called when a message is received by the server.
Declaration
protected virtual void OnMessageReceived(NetworkEndpoint client, IncomingMessage receivedMessage)
Parameters
Type | Name | Description |
---|---|---|
NetworkEndpoint | client | The client endpoint that sent the message. |
IncomingMessage | receivedMessage | The received message. |
Send(IncomingMessage, DeliveryMethod)
Sends the specified incoming message to others clients.
Declaration
public void Send(IncomingMessage incomingMessage, DeliveryMethod deliveryMethod)
Parameters
Type | Name | Description |
---|---|---|
IncomingMessage | incomingMessage | |
DeliveryMethod | deliveryMethod | The delivery method. |
Send(IncomingMessage, DeliveryMethod, NetworkEndpoint)
Sends the specified incoming message to the specified client.
Declaration
public void Send(IncomingMessage toSendMessage, DeliveryMethod deliveryMethod, NetworkEndpoint destinationClient)
Parameters
Type | Name | Description |
---|---|---|
IncomingMessage | toSendMessage | |
DeliveryMethod | deliveryMethod | The delivery method. |
NetworkEndpoint | destinationClient | The destination client. |
Send(IncomingMessage, DeliveryMethod, IEnumerable<NetworkEndpoint>)
Sends the specified incoming message to the specified clients.
Declaration
public void Send(IncomingMessage toSendMessage, DeliveryMethod deliveryMethod, IEnumerable<NetworkEndpoint> destinationClients)
Parameters
Type | Name | Description |
---|---|---|
IncomingMessage | toSendMessage | |
DeliveryMethod | deliveryMethod | The delivery method. |
IEnumerable<NetworkEndpoint> | destinationClients | The destination clients. |
Send(OutgoingMessage, DeliveryMethod)
Sends the specified outgoing message to all the clients.
Declaration
public void Send(OutgoingMessage toSendMessage, DeliveryMethod deliveryMethod)
Parameters
Type | Name | Description |
---|---|---|
OutgoingMessage | toSendMessage | |
DeliveryMethod | deliveryMethod | The delivery method. |
Send(OutgoingMessage, DeliveryMethod, NetworkEndpoint)
Sends the specified outgoing message to the specified client.
Declaration
public void Send(OutgoingMessage toSendMessage, DeliveryMethod deliveryMethod, NetworkEndpoint destinationClient)
Parameters
Type | Name | Description |
---|---|---|
OutgoingMessage | toSendMessage | |
DeliveryMethod | deliveryMethod | The delivery method. |
NetworkEndpoint | destinationClient | The destination client. |
Send(OutgoingMessage, DeliveryMethod, IEnumerable<NetworkEndpoint>)
Sends the specified outgoing message to the specified clients.
Declaration
public void Send(OutgoingMessage toSendMessage, DeliveryMethod deliveryMethod, IEnumerable<NetworkEndpoint> destinationClients)
Parameters
Type | Name | Description |
---|---|---|
OutgoingMessage | toSendMessage | |
DeliveryMethod | deliveryMethod | The delivery method. |
IEnumerable<NetworkEndpoint> | destinationClients | The destination clients. |
ShutdownAsync()
Shutdowns the server.
Declaration
public Task ShutdownAsync()
Returns
Type | Description |
---|---|
Task | A Task representing the asynchronous operation. |
StartAsync()
Starts the server.
Declaration
public Task StartAsync()
Returns
Type | Description |
---|---|
Task | A Task representing the asynchronous operation. |
Events
ClientConnected
Occurs when the server receives a new client connection.
Declaration
public event EventHandler<ClientConnectedEventArgs> ClientConnected
Event Type
Type | Description |
---|---|
EventHandler<ClientConnectedEventArgs> |
Remarks
The incoming message represent the hail message sent by the client.
ClientConnecting
Occurs when the server receives a new client connection request.
Declaration
public event EventHandler<ClientConnectingEventArgs> ClientConnecting
Event Type
Type | Description |
---|---|
EventHandler<ClientConnectingEventArgs> |
ClientDisconnected
Occurs when the server lose the connection with a client.
Declaration
public event EventHandler<ClientDisconnectedEventArgs> ClientDisconnected
Event Type
Type | Description |
---|---|
EventHandler<ClientDisconnectedEventArgs> |
MessageReceived
Occurs when a message is received by the server.
Declaration
public event EventHandler<MessageReceivedEventArgs> MessageReceived
Event Type
Type | Description |
---|---|
EventHandler<MessageReceivedEventArgs> |