Class NatPunchModule
Module for UDP NAT Hole punching operations. Can be accessed from NetManager
Inheritance
Namespace: LiteNetLib
Assembly: LiteNetLib.dll
Syntax
public sealed class NatPunchModule
Fields
MaxTokenLength
Maximum allowed length for the NAT introduction token string.
Declaration
public const int MaxTokenLength = 256
Field Value
| Type | Description |
|---|---|
| int |
UnsyncedEvents
Events automatically will be called without PollEvents method from another thread
Declaration
public bool UnsyncedEvents
Field Value
| Type | Description |
|---|---|
| bool |
Methods
Init(INatPunchListener)
Initializes the NAT punch module with a listener to handle punchthrough events.
Declaration
public void Init(INatPunchListener listener)
Parameters
| Type | Name | Description |
|---|---|---|
| INatPunchListener | listener | The listener implementation that will receive NAT events. |
NatIntroduce(IPEndPoint, IPEndPoint, IPEndPoint, IPEndPoint, string)
Sends NAT introduction packets to both the host and the client to facilitate punchthrough.
Declaration
public void NatIntroduce(IPEndPoint hostInternal, IPEndPoint hostExternal, IPEndPoint clientInternal, IPEndPoint clientExternal, string additionalInfo)
Parameters
| Type | Name | Description |
|---|---|---|
| IPEndPoint | hostInternal | Internal (LAN) endpoint of the host. |
| IPEndPoint | hostExternal | External (WAN) endpoint of the host. |
| IPEndPoint | clientInternal | Internal (LAN) endpoint of the client. |
| IPEndPoint | clientExternal | External (WAN) endpoint of the client. |
| string | additionalInfo | Custom token or data to include in the introduction. |
Remarks
This is typically called by a mediator (e.g. a master server).
PollEvents()
Triggers queued NAT punchthrough events (Success or Request) on the provided INatPunchListener.
Declaration
public void PollEvents()
Remarks
This should be called from the main thread if UnsyncedEvents is false.
SendNatIntroduceRequest(IPEndPoint, string)
Sends a request to the Master Server to introduce this peer to another peer.
Declaration
public void SendNatIntroduceRequest(IPEndPoint masterServerEndPoint, string additionalInfo)
Parameters
| Type | Name | Description |
|---|---|---|
| IPEndPoint | masterServerEndPoint | The endpoint of the Master Server. |
| string | additionalInfo | Custom token to identify the connection or room. |
SendNatIntroduceRequest(string, int, string)
Sends a request to the Master Server to introduce this peer to another peer.
Declaration
public void SendNatIntroduceRequest(string host, int port, string additionalInfo)
Parameters
| Type | Name | Description |
|---|---|---|
| string | host | The hostname or IP of the Master Server. |
| int | port | The port of the Master Server. |
| string | additionalInfo | Custom token to identify the connection or room. |