Class NetworkClient
The network client.
Implements
Inherited Members
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 | Ping interval in seconds. |
float | connectionTimeout | 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 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 hail message to pass. |
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 create outgoing message. |
Disconnect()
Disconnect from server.
Declaration
public void Disconnect()
DiscoverHosts(int)
Emit 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 with the host.
Declaration
protected virtual void OnHostConnected(NetworkEndpoint host)
Parameters
Type | Name | Description |
---|---|---|
NetworkEndpoint | host | The host. |
OnHostDisconnected(NetworkEndpoint)
Called when the client lose 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 endpoint. |
string | serverName | The server name. |
OnMessageReceived(NetworkEndpoint, IncomingMessage)
Called when 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 host.
Declaration
public void Send(OutgoingMessage toSendMessage, DeliveryMethod deliveryMethod)
Parameters
Type | Name | Description |
---|---|---|
OutgoingMessage | toSendMessage | To message to send. |
DeliveryMethod | deliveryMethod | The delivery method. |
Events
HostConnected
Occurs when the client is connected to a host.
Declaration
public event EventHandler<HostConnectedEventArgs> HostConnected
Event Type
Type | Description |
---|---|
EventHandler<HostConnectedEventArgs> |
HostDisconnected
Occurs when the client is disconnected 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 by the client.
Declaration
public event EventHandler<MessageReceivedEventArgs> MessageReceived
Event Type
Type | Description |
---|---|
EventHandler<MessageReceivedEventArgs> |