
NewUPNPMapping event
Fires when new UPnP port mapping was created.
Syntax
- C#
- C++
- VB.NET
delegate void devP2P.NewUPNPMappingEvent(IntPtr Handle, string ExtAddress, string IntAddress, int TCPPort, int UDPPort);
The NewUPNPMapping(Handle,ExtAddress,IntAddress,TCPPort,UDPPort) syntax has these parts:
The NewUPNPMapping(Handle,ExtAddress,IntAddress,TCPPort,UDPPort) syntax has these parts:
Handle | Reference to the devP2P instance. |
ExtAddress | IP address on UPNP device. |
IntAddress | Our IP address. |
TCPPort | TCP port on the UPNP device that forwards back to us. |
UDPPort | UDP port on the UPNP device that forwards back to us. |
void NewUPNPMapping(CP2P *p2p, char *ExtAddress, char *IntAddress, int TCPPort, int UDPPort);
The NewUPNPMapping(p2p,ExtAddress,IntAddress,TCPPort,UDPPort) syntax has these parts:
The NewUPNPMapping(p2p,ExtAddress,IntAddress,TCPPort,UDPPort) syntax has these parts:
p2p | Pointer to devP2P instance that fired the event. |
ExtAddress | Points to buffer with external IP address on UPNP device. |
IntAddress | Points to buffer with our IP address. |
TCPPort | TCP port on the UPNP device that forwards back to us. |
UDPPort | UDP port on the UPNP device that forwards back to us. |
Delegate Sub P2P_NewUPNPMappingEvent(ByVal Handle As IntPtr, ByVal ExtAddress As String, ByVal IntAddress As String, ByVal TCPPort As Integer, ByVal UDPPort As Integer)
The NewUPNPMapping(Handle,ExtAddress,IntAddress,TCPPort,UDPPort) syntax has these parts:
The NewUPNPMapping(Handle,ExtAddress,IntAddress,TCPPort,UDPPort) syntax has these parts:
Handle | Reference to the devP2P instance. |
ExtAddress | IP address on UPNP device. |
IntAddress | Points to buffer with our IP address. |
TCPPort | TCP port on the UPNP device that forwards back to us. |
UDPPort | UDP port on the UPNP device that forwards back to us. |
Remarks
NewUPnPMapping event is fired when devP2P maps external port on UPnP device (usually firewall or router device) so that remote peer can connect to that device to establish connection with your devP2P instance. You do not need to make any special setup on your that device - as long as UPnP service is provided, devP2P will know how to use it.You should, however, call UPNPInit in your code to enable UPnP.
To use this event, you should implement function by yourself in the code (based on function declaration), and set devP2P.Events.NewUPNPMapping structure member to point to your function.
Code sample
- C++
void p2p_NewUPNPMapping(devP2Plib::CP2P *p2p, char *ExtAddress, char *IntAddress, int TCPPort, int UDPPort)
{
if (TCPPort) printf("%s] New TCP mapping: %s->%s (%d)\r\n", p2p->MyName, ExtAddress, IntAddress, TCPPort);
if (UDPPort) printf("%s] New UDP mapping: %s->%s (%d)\r\n", p2p->MyName, ExtAddress, IntAddress, UDPPort);
}
int main(int argc, char **argv)
{
/* ... */
devP2Plib::CP2P *p1 = devP2Plib::CP2P::Create();
/* ... */
p1->Events.NewUPNPMapping = p2p_NewUPNPMapping;
/* ... */
}
{
if (TCPPort) printf("%s] New TCP mapping: %s->%s (%d)\r\n", p2p->MyName, ExtAddress, IntAddress, TCPPort);
if (UDPPort) printf("%s] New UDP mapping: %s->%s (%d)\r\n", p2p->MyName, ExtAddress, IntAddress, UDPPort);
}
int main(int argc, char **argv)
{
/* ... */
devP2Plib::CP2P *p1 = devP2Plib::CP2P::Create();
/* ... */
p1->Events.NewUPNPMapping = p2p_NewUPNPMapping;
/* ... */
}
Platforms
WindowsMac OSX
Linux
BSD