TNet 3  3.0.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros
TNet.UPnP Class Reference

Universal Plug & Play functionality: auto-detect external IP and open external ports. Technically this class would be a fair bit shorter if I had used an XML parser... However I'd rather not, as adding the XML library also adds 1 megabyte to the executable's size in Unity. More...

Public Types

enum  Status { Status.Inactive, Status.Searching, Status.Success, Status.Failure }
 

Public Member Functions

delegate void OnPortRequest (UPnP up, int port, ProtocolType protocol, bool success)
 
void Close ()
 Close all ports that we've opened. More...
 
void WaitForThreads ()
 Wait for all threads to finish. More...
 
void OpenTCP (int port)
 Open up a TCP port on the gateway. More...
 
void OpenUDP (int port)
 Open up a UDP port on the gateway. More...
 
void OpenTCP (int port, OnPortRequest callback)
 Open up a TCP port on the gateway. More...
 
void OpenUDP (int port, OnPortRequest callback)
 Open up a UDP port on the gateway. More...
 
void Start ()
 Start UPnP and attempt to find the gateway. If you want to pause until the gateway is discovered, use WaitForThreads(). More...
 
void CloseTCP (int port)
 Stop port forwarding that was set up earlier. More...
 
void CloseUDP (int port)
 Stop port forwarding that was set up earlier. More...
 
void CloseTCP (int port, OnPortRequest callback)
 Stop port forwarding that was set up earlier. More...
 
void CloseUDP (int port, OnPortRequest callback)
 Stop port forwarding that was set up earlier. More...
 

Public Attributes

string name = "TNetServer"
 Name that will show up on the gateway's list. More...
 

Properties

Status status [get]
 Current UPnP status. More...
 
IPAddress gatewayAddress [get]
 Gateway's IP address, such as 192.168.1.1 More...
 
bool hasThreadsActive [get]
 Whether there are threads active. More...
 

Detailed Description

Universal Plug & Play functionality: auto-detect external IP and open external ports. Technically this class would be a fair bit shorter if I had used an XML parser... However I'd rather not, as adding the XML library also adds 1 megabyte to the executable's size in Unity.

Example usage: UPnP p = new UPnP(); p.OpenTCP(5127);

Don't worry about closing ports. This class will do it for you when its instance gets destroyed.

Member Enumeration Documentation

Enumerator
Inactive 
Searching 
Success 
Failure 

Member Function Documentation

void TNet.UPnP.Close ( )

Close all ports that we've opened.

void TNet.UPnP.CloseTCP ( int  port)

Stop port forwarding that was set up earlier.

void TNet.UPnP.CloseTCP ( int  port,
OnPortRequest  callback 
)

Stop port forwarding that was set up earlier.

void TNet.UPnP.CloseUDP ( int  port)

Stop port forwarding that was set up earlier.

void TNet.UPnP.CloseUDP ( int  port,
OnPortRequest  callback 
)

Stop port forwarding that was set up earlier.

delegate void TNet.UPnP.OnPortRequest ( UPnP  up,
int  port,
ProtocolType  protocol,
bool  success 
)
void TNet.UPnP.OpenTCP ( int  port)

Open up a TCP port on the gateway.

void TNet.UPnP.OpenTCP ( int  port,
OnPortRequest  callback 
)

Open up a TCP port on the gateway.

void TNet.UPnP.OpenUDP ( int  port)

Open up a UDP port on the gateway.

void TNet.UPnP.OpenUDP ( int  port,
OnPortRequest  callback 
)

Open up a UDP port on the gateway.

void TNet.UPnP.Start ( )

Start UPnP and attempt to find the gateway. If you want to pause until the gateway is discovered, use WaitForThreads().

void TNet.UPnP.WaitForThreads ( )

Wait for all threads to finish.

Member Data Documentation

string TNet.UPnP.name = "TNetServer"

Name that will show up on the gateway's list.

Property Documentation

IPAddress TNet.UPnP.gatewayAddress
get

Gateway's IP address, such as 192.168.1.1

bool TNet.UPnP.hasThreadsActive
get

Whether there are threads active.

Status TNet.UPnP.status
get

Current UPnP status.


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