Class NetworkServer
Represents the network server.
Implements
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 | The ping interval in seconds. |
float | connectionTimeout | The connection timeout in seconds. |
string | serverName | The server name 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 of the message. |
Returns
Type | Description |
---|---|
OutgoingMessage | The newly created outgoing message. |
OnClientConnected(NetworkEndpoint, IncomingMessage)
Called when the client is connected.
Declaration
protected virtual void OnClientConnected(NetworkEndpoint client, IncomingMessage hailMessage)
Parameters
Type | Name | Description |
---|---|---|
NetworkEndpoint | client | The client's endpoint. |
IncomingMessage | hailMessage | The hail message received from the client. |
OnClientDisconnected(NetworkEndpoint)
Called when the client disconnects.
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 message received. |
Send(IncomingMessage, DeliveryMethod)
Sends the specified incoming message to other 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 designated 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 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()
Shuts down 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 represents 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 loses 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> |