Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8640395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:16:11+00:00 2026-06-12T11:16:11+00:00

I finished a P2P program in Java that is working perfectly in LAN range,

  • 0

I finished a P2P program in Java that is working perfectly in LAN range, and now I’m stuck at the well-known NAT traversal problem. I want to allow my users to connect to each other passing through the NAT boundaries (I know that is impossible to have a 100% about it). I’ve read a lot about the subject and, although I’ve understood the concept, I still have doubts doing a TCP hole puching.

What I want to do is to connect two clients to each other (they live under the same NAT), which ips are, respectively, 192.168.100.1 and 192.168.100.2 (they can connect to each other directly). They first connect to a PHP server through sockets at the port 80. The server register its public ips and ports, something like that:

Client 1: 200.000.000.1:1478
Client 2: 120.000.000.1:2547

And the Java sockets of each client returns, upon connection, for instance:

Client 1: Socket[addr=/xx.xx.xx.xx,port=80,localport=54632]
Client 2: Socket[addr=/xx.xx.xx.xx,port=80,localport=41789]

Id est, beyond two tcp connections open with the server through port 80, I also have the private ip, the public ip, the local port and the public port of each client. Then, that’s my problem. From now on I don’t know how to proceed. What I read was not very clear to me about this step.

Is necessary to have the two clients listening on public ports (1478-2547) or local ports (54632-41789)? Simultaneously making them try to connect on public or private of the other? How many other sockets I need to open? I’ve done some tests, but I think something is wrong (*connection refused*).

Any help will be welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:16:13+00:00Added an answer on June 12, 2026 at 11:16 am

    There are different ways to proceed.

    1. You could implement some kind of proxy. Both Clients connect to it (outside NAT-Barrier) and have it route their messages.
    2. If you want direct connections Client2Client, your users will have to open a port on their NAT-Barrier and forward it to the local IP.

    That’s annoying but that’s also how it works.

    For Client A it’s useless to know Client B’s local data, because he won’t be able to reach it.
    To your last few questions: Local Client A listens on a port lets say X , then Local Client B has to connect to the public IP of Client A’s network. Probably that’s a router. There, the port has to be configured to be forwarded to Local Client A. That’s all.
    If you follow possibility #1 (see above) you’ll have to have a public service listening on port X, to which Clients A and B connect. Since these will be outgoing connections to a public IP, no Holepunching is needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Almost finished my java web app. All working fine. Whats next. I need now
I finished a Java Program, and now i'm creating a Batch File to set
I've almost finished my Java p2p file sharing application and given that it's pretty
I finished the English version of my application and now I am working on
I finished the English version of my application and now I am working on
I finished Michael Hartl's Ruby on Rails Tutorial. Now I'm working on the suggested
I finished building an app that allows beaming of photos, contacts and text clips
I finished NerdDinner tutorial and now I'm playing a bit with project. Index page
Just finished reading this blog post: http://www.skorks.com/2010/03/an-interview-question-that-prints-out-its-own-source-code-in-ruby/ In it, the author argues the case
Just finished up my first mvc4 app. Everything is working great until I deploy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.