UDP hole punching P2p
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: UDP hole punching P2p

  1. #1
    Join Date
    Nov 2008
    Location
    india
    Posts
    53

    Exclamation UDP hole punching P2p

    I am working UDP hole punching to have communication between two client inC# without WCF.
    presenlty both my client are behind same NAT i.e in my company's network.
    I am able to get public IP of both the client by requesting to the STUN server.
    there is a server app which will act as relaying server.this server provide the
    client about other clients Public IP and port.
    suppose

    Client A private IP 192.168.1.192 port 4005 public IP 123.45.67.1 port 45667
    Client B private IP 192.168.1.100 port 7005 public IP 143.45.67.1 port 35667

    now the question is how to start connection between these two client

    1. shall I create a server socket in ClientA which will listen to port 4005
    and in Client B at port 7005 so that each can recive message at 4005 and 7005
    respectively.
    so when ClientB send some data to ClientB at public IP 123.45.67.1 port 45667
    it will arrive at 4005 port at clientA and vice varsa.

    please confirm my understanding.if it is wrong way to do this then pease
    suggest correct way to implement UDP hole punching.

  2. #2
    Join Date
    Nov 2008
    Location
    india
    Posts
    53

    Re: UDP hole punching P2p

    Its Done .............problem was due to NAT mapping .

  3. #3
    Join Date
    Feb 2011
    Posts
    3

    Re: UDP hole punching P2p

    hi lok.vikram
    i am also trying to implement the UDP Hole punching behind the NAT but it's not happening.I think i am also facing same problem.Will you please share with us what was the problem in NAT and how u overcome it

  4. #4
    Join Date
    Nov 2008
    Location
    india
    Posts
    53

    Re: UDP hole punching P2p

    I don know how you are implementing it.Do you have rendvous server or not.it is mandatory for NAt punching.

    client 1
    1. create a listener thread which will listen to a port say 40000.
    2. use same port to connect with the other peer.

    client 2
    1. create a listener thread which will listen to a port say 30000.
    2. use same port to connect with the other peer.

    step 2 in both client should happen simultaneously

    rdv server
    which will exchange the IP address to two peer trying to connect.
    I wanted to know how you are implementing it.

    Best of luck
    Last edited by lok.vikram; February 23rd, 2011 at 12:39 AM.

  5. #5
    Join Date
    Feb 2011
    Posts
    3

    Re: UDP hole punching P2p

    hi lok.vikram

    Thanks for u r reply.

    I am doing same what u told here.

    Please Clear me the following point.

    1. Client 1 And Client 2 both has Public IP and Public Port. Will the public port and private port may differ when they communicating with server ??? For say Client 1 public port 4000 and private port 3000 . if yes then client 1 , which port will use to listen and which port for use for connect ???

    2. Rendezvous server will only exchange the client 1 and client 2 's public and private IP and port and while try to connect p2p we use the same port which already used for communicate to Rendezvous server. Am i missing anything about Rendezvous server ???

    I have a request, if u give me the mail id i can send u the code ...
    My mail id sufi2008@gmail.com.

    Please help me.....

  6. #6
    Join Date
    Feb 2011
    Posts
    3

    Re: UDP hole punching P2p

    Hi lok.vikram

    "Its Done .............problem was due to NAT mapping"

    Please share with us what was the problem was due to NAT mapping ???

  7. #7
    Join Date
    Nov 2008
    Location
    india
    Posts
    53

    Re: UDP hole punching P2p

    1. Client 1 And Client 2 both has Public IP and Public Port. Will the public port and private port may differ when they communicating with server ??? For say Client 1 public port 4000 and private port 3000 . if yes then client 1 , which port will use to listen and which port for use for connect ???

    Note:while connecting P2P donot use private address for time being later you can add private address for p2p.my suggestion is based based on public address for time being.

    ans:Yes public and private port may differ since NAT is involved. here 3000(local port) is mapped to 4000(public port) by NAT.you need to listen to local port only .

    client Create udp sockey say m_Sock not need to bind local address if you are using public address.use this socket to connect with server.

    create a listener thread where use m_Sock in select() (in C++ ) to listen for incoming mesage from server or p2p client.

    then connect the other P2P client(use public address and port) using same m_Sock.same need to repeated in other client as well.

    2. Rendezvous server will only exchange the client 1 and client 2 's public and private IP and port and while try to connect p2p we use the same port which already used for communicate to Rendezvous server. Am i missing anything about Rendezvous server ???

    Ans:Correct you need to use same port for P2P.

    I have a request, if u give me the mail id i can send u the code ...
    My mail id sufi2008@gmail.com.

    Please help me.....[/QUOTE]

  8. #8
    Join Date
    Oct 2011
    Posts
    1

    Re: UDP hole punching P2p

    I have a really stupid question.


    How would i go about creating a rendevouz server or is there an open source one out there like for linux i can use for my middle man? I think this is what im needing to accomplish my goal of creating my own teamviewer/logmein

  9. #9
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,553

    Re: UDP hole punching P2p

    The "hole punching" technique is described in the excellent paper "Peer-to-Peer Communication Across Network Address Translators" by Bryan Ford, Pyda Srisuresh, Dan Kegel at http://www.brynosaurus.com/pub/net/p2pnat/ . Bryan Ford's site (at http://midcom-p2p.sourceforge.net/ ) includes a link to source code for "hole punching".

    Mike

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center