Diarkis C# Client SDK
Classes | Public Member Functions | Public Attributes | Events | List of all members
Diarkis.Modules.P2P Class Reference

Peer-to-Peer client that uses Diarksi Udp class instance internally. NOTE: If the client is a mobile device and the client address changes, peer-to-peer communication will break. More...

Public Member Functions

delegate void ReadyHandler (string addr, int port, double holePunchTimeInMilliseconds)
 Event raised when peer-to-peer comminucation is successfully established. More...
 
delegate void TerminateHandler (string addr, int port)
 Event raised when peer-to-peer comminucation fails to establish. More...
 
delegate void MessageHandler (string addr, int port, byte[] packet)
 Event raised when the peer sends a message via Send or RSend. More...
 
delegate void ExceptionHandler (int errCode, string errMsg)
 Event raised when socket related exception is thrown. More...
 
 P2P (Udp udp)
 Creates a P2P peer and communication wit the peer. One P2P instance = One P2P peer. More...
 
void SetResendTime (ushort resendTime)
 Sets resend time in milliseconds for RSend. Default value of resent time is 1000ms. NOTE: Setting this value too small may lead to unecessary CPU workloads. More...
 
void Update ()
 Must be called a certain interval from the main thread. For Unity application this must be called in Update. More...
 
bool IsConnected ()
 Returns true if we are connected (hole punch successfully completed) with the peer. More...
 
string GetPeerAddress ()
 Rerturns the peer address and port as a string. More...
 
bool IsSamePeer (string addr, int port)
 Returns true if the address and port match its address and port. More...
 
void Connect (string publicAddress, string[] localAddresses, ushort timeoutInMilliseconds=3000)
 Starts P2P connection with a peer: When it's successful, it triggers OnReady event and when it fails triggers OnFail event. The peer must be invoking Connect also for this to work as this is a hole punching operation. More...
 
void Disconnect ()
 Stops P2P communication with the peer. More...
 
void Send (byte[] msg)
 Sensd a P2P message to the peer. More...
 
void RSend (byte[] msg)
 Sends a P2P message as a reliable packet. Guarantees the delivery and order of the message. More...
 

Public Attributes

string UID
 Client unique user ID to be set and used. More...
 

Events

ReadyHandler OnReady
 
TerminateHandler OnFail
 
MessageHandler OnMessage
 
MessageHandler OnReliableMessage
 
ExceptionHandler OnException
 
TerminateHandler OnDisconnect
 

Detailed Description

Peer-to-Peer client that uses Diarksi Udp class instance internally. NOTE: If the client is a mobile device and the client address changes, peer-to-peer communication will break.

Constructor & Destructor Documentation

◆ P2P()

Diarkis.Modules.P2P.P2P ( Udp  udp)
inline

Creates a P2P peer and communication wit the peer. One P2P instance = One P2P peer.

Member Function Documentation

◆ Connect()

void Diarkis.Modules.P2P.Connect ( string  publicAddress,
string[]  localAddresses,
ushort  timeoutInMilliseconds = 3000 
)
inline

Starts P2P connection with a peer: When it's successful, it triggers OnReady event and when it fails triggers OnFail event. The peer must be invoking Connect also for this to work as this is a hole punching operation.

Parameters
publicAddressPublic address of the peer to start P2P with. The string format is "{address}:{port}".
Parameters
localAddressesAn array of local addresses of the peer. If the public address of the peer is the same as yours, hole punching fails. The local address list will be used to complete the hole punch instead.
timeoutInMillisecondsTimeout in milliseconds. When this time exceeds before successfully completing hole punching with the peer. It will trigger OnFail event. Default is 3000ms.

◆ Disconnect()

void Diarkis.Modules.P2P.Disconnect ( )
inline

Stops P2P communication with the peer.

◆ ExceptionHandler()

delegate void Diarkis.Modules.P2P.ExceptionHandler ( int  errCode,
string  errMsg 
)

Event raised when socket related exception is thrown.

◆ GetPeerAddress()

string Diarkis.Modules.P2P.GetPeerAddress ( )
inline

Rerturns the peer address and port as a string.

◆ IsConnected()

bool Diarkis.Modules.P2P.IsConnected ( )
inline

Returns true if we are connected (hole punch successfully completed) with the peer.

◆ IsSamePeer()

bool Diarkis.Modules.P2P.IsSamePeer ( string  addr,
int  port 
)
inline

Returns true if the address and port match its address and port.

◆ MessageHandler()

delegate void Diarkis.Modules.P2P.MessageHandler ( string  addr,
int  port,
byte[]  packet 
)

Event raised when the peer sends a message via Send or RSend.

Parameters
addrPeer client address.
portPeer client port.
packetMessage byte array sent from the peer.

◆ ReadyHandler()

delegate void Diarkis.Modules.P2P.ReadyHandler ( string  addr,
int  port,
double  holePunchTimeInMilliseconds 
)

Event raised when peer-to-peer comminucation is successfully established.

Parameters
addrPeer client address.
portPeer client port.
holePunchTimeInMillisecondsTime in milliseconds it took to complete hole punching (establishing peer-to-peer communication).

◆ RSend()

void Diarkis.Modules.P2P.RSend ( byte[]  msg)
inline

Sends a P2P message as a reliable packet. Guarantees the delivery and order of the message.

Parameters
msgMessage byte array to be sent.

◆ Send()

void Diarkis.Modules.P2P.Send ( byte[]  msg)
inline

Sensd a P2P message to the peer.

Parameters
msgMessage byte array.

◆ SetResendTime()

void Diarkis.Modules.P2P.SetResendTime ( ushort  resendTime)
inline

Sets resend time in milliseconds for RSend. Default value of resent time is 1000ms. NOTE: Setting this value too small may lead to unecessary CPU workloads.

◆ TerminateHandler()

delegate void Diarkis.Modules.P2P.TerminateHandler ( string  addr,
int  port 
)

Event raised when peer-to-peer comminucation fails to establish.

Parameters
addrPeer client address.
portPeer client port.

◆ Update()

void Diarkis.Modules.P2P.Update ( )
inline

Must be called a certain interval from the main thread. For Unity application this must be called in Update.

Member Data Documentation

◆ UID

string Diarkis.Modules.P2P.UID

Client unique user ID to be set and used.


The documentation for this class was generated from the following file: