Back to product page

Link method


Initiates connection with remote peer.

Type

Integer.

Syntax

  • C#
  • C++
  • VB.NET
int devP2P.Link(IntPtr Handle, string peerXML);
The Link(Handle,peerXML) syntax has these parts:
HandleReference to the devP2P instance.
peerXMLXML containing list of IP address where remote listens.
Return value0 (ErrorNone) if success, otherwise negative value from Errors enumeration.

int Link(char *peerXML);
The Link(peerXML) syntax has these parts:
peerXMLXML containing list of IP address where remote listens.
Return value0 (ErrorNone) if success, otherwise negative value from Errors enumeration.

Function P2P_Link(ByVal Handle As IntPtr, ByVal peerXML As String) As Integer
The Link(Handle,peerXML) syntax has these parts:
HandleReference to the devP2P instance.
peerXMLXML containing list of IP address where remote listens.
Return value0 (ErrorNone) if success, otherwise negative value from Errors enumeration.

Remarks

The Link method will try to connect to remote devP2P. Connection is attempted both with UDP and TCP packets (based on Start method arguments). Besides persistent TCP connection, devP2P implements "reliable UDP" connection between two peers, and forwards all traffic through it, whatever succeeds first.

In order for Link to be successful, you should provide peerXML details, structured XML containing IP and Port details, where component should try to connect to. Typically, you will get this value in SearchDone event, but you can fill it by yourself if you know where remote peer listens, and want to try to establish direct connection with known parameters.

If local devP2P connects to remote devP2P, LinkDone event will be fired. Initial "handshake" will be performed prior to firing this event. All packets that are sent to remote side are encrypted using AES algorithm using key set in the SetPassword method. Both sides, of course, must use same password otherwise remote peer's data is unreadable.

Once LinkDone event is fired, you can, for example, send text, files, or get reference to any of free forward channels (through GetForward method), set up it's properties, and call StartForward to start forwarding traffic.

Typically, peerXML will look like this - specifies type of connection (TCP/UDP), IP and port, and possibly type of connection when specified:
 
<UDP Type="Mediator" IP="81.127.37.44" Port="52133"/>
<UDP IP="192.168.42.1" Port="61517"/>
<TCP IP="192.168.42.1" Port="19815"/>
<UDP IP="192.168.111.1" Port="61517"/>
<TCP IP="192.168.111.1" Port="19815"/>
<UDP IP="25.145.193.136" Port="61517"/>
<TCP IP="25.145.193.136" Port="19815"/>
<UDP IP="192.168.192.8" Port="61517"/>
<TCP IP="192.168.192.8" Port="19815"/>
<UDP IP="81.127.37.44" Port="61517"/>
<TCP IP="81.127.37.44" Port="19815"/>
<TCP Type="Relay" IP="1.2.3.4" Port="123"/>
 

XML elements are pretty much self explanatory. Besides setting UDP/TCP xml entry, you must define IP and Port attributes. If Type="Mediator" is set, devP2P will try to perform "UDP Hole Punching" on specified IP/Port to penetrate through remote firewall. If Type="Relay" then devP2P will not attempt to establish connection with it immediately, but will wait first few direct attempts, and when number of attempts defined by LinkingRelayDelay passes, it will attempt to connect through relay too.

Platforms

Windows
Mac OSX
Linux
BSD