Class NetworkClient
Represents the network client.
Implements
Namespace: Evergine.Networking.Connection
Assembly: Evergine.Networking.dll
Syntax
public class NetworkClient : INetworkClient
Constructors
NetworkClient(string, float, float)
Initializes a new instance of the NetworkClient class.
Declaration
public NetworkClient(string applicationIdentifier, float pingInterval, float connectionTimeout)
Parameters
Type | Name | Description |
---|---|---|
string | applicationIdentifier | The application identifier. |
float | pingInterval | The ping interval in seconds. |
float | connectionTimeout | The connection timeout in seconds. |
Properties
Identifier
Gets the identifier.
Declaration
public long Identifier { get; }
Property Value
Type | Description |
---|---|
long | The identifier. |
IsConnected
Gets a value indicating whether this instance is connected.
Declaration
public bool IsConnected { get; }
Property Value
Type | Description |
---|---|
bool |
|
Methods
Connect(NetworkEndpoint)
Connects to a remote host.
Declaration
public void Connect(NetworkEndpoint host)
Parameters
Type | Name | Description |
---|---|---|
NetworkEndpoint | host | The remote host's endpoint to connect to. |
Connect(NetworkEndpoint, OutgoingMessage)
Connects to a remote host.
Declaration
public void Connect(NetworkEndpoint host, OutgoingMessage hailMessage)
Parameters
Type | Name | Description |
---|---|---|
NetworkEndpoint | host | The remote host endpoint to connect to. |
OutgoingMessage | hailMessage | The greeting message to send. |
CreateMessage(MessageType)
Creates a new outgoing message.
Declaration
public OutgoingMessage CreateMessage(MessageType type = MessageType.Data)
Parameters
Type | Name | Description |
---|---|---|
MessageType | type | The message type. |
Returns
Type | Description |
---|---|
OutgoingMessage | The created outgoing message. |
Disconnect()
Disconnects from the server.
Declaration
public void Disconnect()
DiscoverHosts(int)
Emits a discovery signal to all hosts on your subnet. Hosts with the same appId and port will be notified by the HostDisconnected event.
Declaration
public void DiscoverHosts(int port)
Parameters
Type | Name | Description |
---|---|---|
int | port | The expected port. |
OnHostConnected(NetworkEndpoint)
Called when the client connects to the host.
Declaration
protected virtual void OnHostConnected(NetworkEndpoint host)
Parameters
Type | Name | Description |
---|---|---|
NetworkEndpoint | host | The host. |
OnHostDisconnected(NetworkEndpoint)
Called when the client loses the connection with the host.
Declaration
protected virtual void OnHostDisconnected(NetworkEndpoint host)
Parameters
Type | Name | Description |
---|---|---|
NetworkEndpoint | host | The host endpoint. |
OnHostDiscovered(NetworkEndpoint, string)
Called when a host with the same application identifier is discovered.
Declaration
protected virtual void OnHostDiscovered(NetworkEndpoint host, string serverName)
Parameters
Type | Name | Description |
---|---|---|
NetworkEndpoint | host | The discovered host's endpoint. |
string | serverName | The server name. |
OnMessageReceived(NetworkEndpoint, IncomingMessage)
Called when a message is received.
Declaration
protected virtual void OnMessageReceived(NetworkEndpoint host, IncomingMessage receivedMessage)
Parameters
Type | Name | Description |
---|---|---|
NetworkEndpoint | host | The host endpoint that sent the message. |
IncomingMessage | receivedMessage | The received message. |
Send(OutgoingMessage, DeliveryMethod)
Sends the specified message to the host.
Declaration
public void Send(OutgoingMessage toSendMessage, DeliveryMethod deliveryMethod)
Parameters
Type | Name | Description |
---|---|---|
OutgoingMessage | toSendMessage | The message to send. |
DeliveryMethod | deliveryMethod | The delivery method. |
Events
HostConnected
Occurs when the client connects to a host.
Declaration
public event EventHandler<HostConnectedEventArgs> HostConnected
Event Type
Type | Description |
---|---|
EventHandler<HostConnectedEventArgs> |
HostDisconnected
Occurs when the client disconnects from the host.
Declaration
public event EventHandler<HostDisconnectedEventArgs> HostDisconnected
Event Type
Type | Description |
---|---|
EventHandler<HostDisconnectedEventArgs> |
HostDiscovered
Occurs when a new host with the same application identifier is discovered.
Declaration
public event EventHandler<HostDiscoveredEventArgs> HostDiscovered
Event Type
Type | Description |
---|---|
EventHandler<HostDiscoveredEventArgs> |
MessageReceived
Occurs when a host message is received from the client.
Declaration
public event EventHandler<MessageReceivedEventArgs> MessageReceived
Event Type
Type | Description |
---|---|
EventHandler<MessageReceivedEventArgs> |