Skip to content

Exomia.Network

Daniel Baetz edited this page Jun 19, 2019 · 28 revisions

ClientBase

A TCP/UDP-Client base.

public abstract class Exomia.Network.ClientBase
    : IClient, IDisposable

Fields

Type Name Summary
Socket _clientSocket The client socket.
Byte _state The state.

Properties

Type Name Summary
Int32 Port Port.
String ServerAddress ServerAddress.

Events

Type Name Summary
DisconnectedHandler Disconnected called than the client is Disconnected.
Action<PingPacket> Ping called than a ping is received.

Methods

Type Name Summary
void AddCommand(UInt32 commandid, DeserializePacketHandler<Object> deserialize) add a command.
void AddDataReceivedCallback(UInt32 commandid, DataReceivedHandler callback) add a data received callback.
SendError BeginSendData(UInt32 commandid, Byte[] data, Int32 offset, Int32 length, UInt32 responseID) Begins send data.
Boolean Connect(IPAddress[] ipAddresses, Int32 port, Int32 timeout = 10)
Boolean Connect(String serverAddress, Int32 port, Int32 timeout = 10)
void DeserializeData(UInt32 commandid, Byte[] data, Int32 offset, Int32 length, UInt32 responseid) Deserialize data.
void Disconnect()
void Disconnect(DisconnectReason reason)
void Dispose()
void Finalize() ClientBase destructor.
void OnDispose(Boolean disposing) OnDispose.
void ReceiveAsync() Receive asynchronous.
void RemoveCommand(UInt32 commandid) remove a command.
void RemoveDataReceivedCallback(UInt32 commandid, DataReceivedHandler callback) remove a data received callback.
SendError Send(UInt32 commandid, Byte[] data, Int32 offset, Int32 length)
SendError Send(UInt32 commandid, ISerializable serializable)
SendError Send(UInt32 commandid, T& data)
SendError SendPing()
Task<Response<TResult>> SendR(UInt32 commandid, Byte[] data, Int32 offset, Int32 length)
Task<Response<TResult>> SendR(UInt32 commandid, Byte[] data, Int32 offset, Int32 length, DeserializePacketHandler<TResult> deserialize)
Task<Response<TResult>> SendR(UInt32 commandid, Byte[] data, Int32 offset, Int32 length, TimeSpan timeout)
Task<Response<TResult>> SendR(UInt32 commandid, Byte[] data, Int32 offset, Int32 length, DeserializePacketHandler<TResult> deserialize, TimeSpan timeout)
Task<Response<TResult>> SendR(UInt32 commandid, ISerializable serializable)
Task<Response<TResult>> SendR(UInt32 commandid, ISerializable serializable, DeserializePacketHandler<TResult> deserialize)
Task<Response<TResult>> SendR(UInt32 commandid, ISerializable serializable, TimeSpan timeout)
Task<Response<TResult>> SendR(UInt32 commandid, ISerializable serializable, DeserializePacketHandler<TResult> deserialize, TimeSpan timeout)
Task<Response<TResult>> SendR(UInt32 commandid, T& data)
Task<Response<TResult>> SendR(UInt32 commandid, T& data, DeserializePacketHandler<TResult> deserialize)
Task<Response<TResult>> SendR(UInt32 commandid, T& data, TimeSpan timeout)
Task<Response<TResult>> SendR(UInt32 commandid, T& data, DeserializePacketHandler<TResult> deserialize, TimeSpan timeout)
Task<Response<PingPacket>> SendRPing()
Boolean TryCreateSocket(Socket& socket) Attempts to create socket.

Static Fields

Type Name Summary
Byte RECEIVE_FLAG The receive flag.
Byte SEND_FLAG The send flag.

CommandID

CommandID.

public static class Exomia.Network.CommandID

Static Fields

Type Name Summary
UInt32 CONNECT CONNECT_ID.
UInt32 DISCONNECT DISCONNECT_ID.
UInt32 PING PING_ID.

CompressionMode

Values that represent CompressionMode. MASK 0b00111000.

public enum Exomia.Network.CompressionMode
    : Enum, IComparable, IFormattable, IConvertible

Enum

Value Name Summary
0 None None
32 Lz4 LZ4

DisconnectReason

can be used to determine if a client has disconnected properly.

public enum Exomia.Network.DisconnectReason
    : Enum, IComparable, IFormattable, IConvertible

Enum

Value Name Summary
0 Unspecified Unspecified/Unknown Reason
1 Graceful Graceful
2 Aborted Aborted
3 Error Error

EncryptionMode

Values that represent EncryptionMode. MASK 0b00000111.

public enum Exomia.Network.EncryptionMode
    : Enum, IComparable, IFormattable, IConvertible

Enum

Value Name Summary
0 None None
4 End2End End2End

IClient

IClient interface.

public interface Exomia.Network.IClient
    : IDisposable

Methods

Type Name Summary
Boolean Connect(String serverAddress, Int32 port, Int32 timeout = 10) try's to connect the client to a server.
Boolean Connect(IPAddress[] ipAddresses, Int32 port, Int32 timeout = 10) try's to connect the client to a server.
void Disconnect() call to disconnect from a server.
SendError Send(UInt32 commandid, Byte[] data, Int32 offset, Int32 length) send data to the server.
SendError Send(UInt32 commandid, ISerializable serializable) send data to the server.
SendError Send(UInt32 commandid, T& data) send data to the server.
SendError SendPing() send a ping command to the server.
Task<Response<TResult>> SendR(UInt32 commandid, Byte[] data, Int32 offset, Int32 length) send data to the server.
Task<Response<TResult>> SendR(UInt32 commandid, Byte[] data, Int32 offset, Int32 length, DeserializePacketHandler<TResult> deserialize) send data to the server.
Task<Response<TResult>> SendR(UInt32 commandid, Byte[] data, Int32 offset, Int32 length, TimeSpan timeout) send data to the server.
Task<Response<TResult>> SendR(UInt32 commandid, Byte[] data, Int32 offset, Int32 length, DeserializePacketHandler<TResult> deserialize, TimeSpan timeout) send data to the server.
Task<Response<TResult>> SendR(UInt32 commandid, ISerializable serializable) send data to the server.
Task<Response<TResult>> SendR(UInt32 commandid, ISerializable serializable, DeserializePacketHandler<TResult> deserialize) send data to the server.
Task<Response<TResult>> SendR(UInt32 commandid, ISerializable serializable, TimeSpan timeout) send data to the server.
Task<Response<TResult>> SendR(UInt32 commandid, ISerializable serializable, DeserializePacketHandler<TResult> deserialize, TimeSpan timeout) send data to the server.
Task<Response<TResult>> SendR(UInt32 commandid, T& data) send data to the server.
Task<Response<TResult>> SendR(UInt32 commandid, T& data, DeserializePacketHandler<TResult> deserialize) send data to the server.
Task<Response<TResult>> SendR(UInt32 commandid, T& data, TimeSpan timeout) send data to the server.
Task<Response<TResult>> SendR(UInt32 commandid, T& data, DeserializePacketHandler<TResult> deserialize, TimeSpan timeout) send data to the server.
Task<Response<PingPacket>> SendRPing() send a ping command to the server.

Packet

Packet readonly struct.

public struct Exomia.Network.Packet

Fields

Type Name Summary
Byte[] Buffer Buffer.
Int32 Length Length.
Int32 Offset Offset.

Response<TResult>

A response.

public struct Exomia.Network.Response<TResult>

Fields

Type Name Summary
TResult Result Result.
SendError SendError SendError.

SendError

Values that represent SendError.

public enum Exomia.Network.SendError
    : Enum, IComparable, IFormattable, IConvertible

Enum

Value Name Summary
0 None No error, all good
1 Socket A socket exception is occured
2 Disposed The socket was disposed
3 Invalid The SEND_FLAG is not set
4 Unknown Unknown error occured

ServerBase<T, TServerClient>

A server base.

public abstract class Exomia.Network.ServerBase<T, TServerClient>
    : IServer<T>, IDisposable

Fields

Type Name Summary
Dictionary<T, TServerClient> _clients Dictionary{T, TServerClient}
Socket _listener The listener.
Int32 _port The port.
Byte _state The state.

Properties

Type Name Summary
Int32 Port Port.

Events

Type Name Summary
ClientActionHandler<T> ClientConnected called than a client is connected.
ClientDisconnectHandler<T> ClientDisconnected called than a client is disconnected.

Methods

Type Name Summary
void AddCommand(UInt32 commandid, DeserializePacketHandler<Object> deserialize) add a command.
void AddDataReceivedCallback(UInt32 commandid, ClientDataReceivedHandler<T, TServerClient> callback) add a data received callback.
Boolean CreateServerClient(T arg0, TServerClient& serverClient) Create a new ServerClient than a client connects.
void DeserializeData(T arg0, UInt32 commandid, Byte[] data, Int32 offset, Int32 length, UInt32 responseid) Deserialize data.
void Dispose()
void Finalize() ServerBase destructor.
void InvokeClientDisconnect(T arg0, DisconnectReason reason) Executes the client disconnect on a different thread, and waits for the result.
void ListenAsync() Listen asynchronous.
void OnAfterClientDisconnect(T arg0) called after Exomia.Network.ServerBase2.InvokeClientDisconnect(0,Exomia.Network.DisconnectReason).
void OnClientConnected(T arg0) called than a new client is connected.
void OnClientDisconnected(T arg0, DisconnectReason reason) called then the client is connected.
void OnDispose(Boolean disposing) OnDispose.
Boolean OnRun(Int32 port, Socket& listener) Executes the run action.
Boolean RemoveCommand(UInt32 commandid) remove a command.
void RemoveDataReceivedCallback(UInt32 commandid, ClientDataReceivedHandler<T, TServerClient> callback) remove a data received callback.
Boolean Run(Int32 port)
SendError SendTo(T arg0, UInt32 commandid, Byte[] data, Int32 offset, Int32 length, UInt32 responseid)
SendError SendTo(T arg0, UInt32 commandid, ISerializable serializable, UInt32 responseid)
SendError SendTo(T arg0, UInt32 commandid, T1& data, UInt32 responseid)
void SendToAll(UInt32 commandid, Byte[] data, Int32 offset, Int32 length)
void SendToAll(UInt32 commandid, T1& data)
void SendToAll(UInt32 commandid, ISerializable serializable)

Static Fields

Type Name Summary
Int32 CLOSE_TIMEOUT The close timeout.
Byte RECEIVE_FLAG The receive flag.
Byte SEND_FLAG The send flag.

ServerClientBase<T>

ServerClientBase{T} class.

public abstract class Exomia.Network.ServerClientBase<T>

Fields

Type Name Summary
T _arg0 Socket

Properties

Type Name Summary
EndPoint EndPoint EndPoint.
IPAddress IPAddress IPAddress.
DateTime LastReceivedPacketTimeStamp LastReceivedPacketTimeStamp.

Methods

Type Name Summary
void SetLastReceivedPacketTimeStamp() Sets last received packet time stamp.