NAT Traversal for UNET
Provides NAT punch-through, automatic port forwarding, and other useful features on top of Unity's UNET HLAPI networking system.
ExternalNetworkConnection Class Reference

Connections used by the NetworkManager to allow the NetworkServer to accept incoming connections on more than one port. More...

Inherits NetworkConnection.

Public Member Functions

new void Disconnect ()
 Disconnect this connection. More...
 
override void Initialize (string networkAddress, int netHostId, int netConnId, HostTopology hostTopology)
 Adds an offset to the connectionId and then calls base.Initialize() More...
 
override bool TransportSend (byte[] bytes, int numBytes, int channelId, out byte error)
 Send some bytes over the network. More...
 

Properties

int offset [get]
 

Detailed Description

Connections used by the NetworkManager to allow the NetworkServer to accept incoming connections on more than one port.

These connections are used by ExternalServer. They get added to NetworkServer via AddExternalConnection. When the connection is initialized we have to add an offset to the networkConnectionId to prevent it overlapping with other connections added to NetworkServer. When the NetworkServer attempts to send data out over the connection we intercept it and un-offset the connectionId to get back to the actual hostId / connectionId combo that we want to use to send.

Member Function Documentation

◆ Disconnect()

new void Disconnect ( )

Disconnect this connection.

Just like the normal Disconnect method except this one uses the proper un-offset connection id.

◆ Initialize()

override void Initialize ( string  networkAddress,
int  netHostId,
int  netConnId,
HostTopology  hostTopology 
)

Adds an offset to the connectionId and then calls base.Initialize()

Parameters
networkAddressThe network address.
netHostIdThe net host identifier.
netConnIdThe net connection identifier.
hostTopologyThe host topology.

◆ TransportSend()

override bool TransportSend ( byte []  bytes,
int  numBytes,
int  channelId,
out byte  error 
)

Send some bytes over the network.

Un-offsets the connectionId to get the id of the connection on the ExternalServer.

Parameters
bytesThe bytes.
numBytesThe number bytes.
channelIdThe channel identifier.
errorThe error.
Returns