aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes how to do port forwarding in java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "how to do port forwarding in java?" Watch "how to do port forwarding in java?" New topic
Author

how to do port forwarding in java?

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
i m new in networking, so i m sorry, if i am asking any silly question.
i read this Port Forwarding.
although port forwarding is used to access private networks, but is it related to java??
i mean is there anything i have to do in java for port forwarding.
i mean to access a private network, do i need to do something in java.
and also i want to know how do i access any private network by port forwarding??
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Your Java code never knows anything about any port forwarding that's going on. It's strictly a router configuration issue.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Punit Jain wrote:
and also i want to know how do i access any private network by port forwarding??


You can't access any network you choose with port forwarding. The administrator of that network has to enable you to access a host on his network by configuring his router appropriately, and informing you of the public IP address of that router. You will never know you're accessing a host on a private network unless he tells you, and you won't care.

That's not a topic for this forum, as it has nothing to do with Java. If you want a place on this site to ask about it, this forum would be your best bet: http://www.coderanch.com/forums/f-59/gc

Ultimately, however, either you are the administrator for a network and you use your router's manual to learn how to configure it to port forward to the internal host that you're positioning as a server, or else it's somebody else's network and he either forwards a port or he doesn't, and you never need to know whether he's doing it.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

No, it isn't related to Java. Not for most meanings of the phrase "related to", anyway. You might say that the front door of the place you live is "related to" the restaurant down the road, because you have to open your front door to get there, but most people wouldn't say that.

If you want to set up port forwarding in your network, then there isn't anything you have to do in Java. Not only that, there isn't anything you can do in Java. It's just a matter of going to the router which connects your private network to the Internet and setting up the appropriate configuration.

As for how you access any private network (I assume you didn't mean your own private network) by port forwarding, here's how you do it: You talk to the person in charge of that private network and ask them to configure port forwarding in their network so that you can access it.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
i apologies for posting this issue in wrong forum.

You talk to the person in charge of that private network and ask them to configure port forwarding in their network so that you can access it.

if possible can you please tell me how to do this, or any resource for this??

Thank you..

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Punit Jain wrote:

You talk to the person in charge of that private network and ask them to configure port forwarding in their network so that you can access it.

if possible can you please tell me how to do this, or any resource for this??


If I were to take this literally, you are asking for a "resource" about how to talk to a person. I'm not going to answer that because it would be absurd. Instead perhaps you could take a minute to put together a coherent question?
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
no actually, i m asking any resource for port forwarding??
that tells me how to do everything, you said..
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Your router should have documentation for that. Every router has a process running which you can access, sometimes via a web application and other times via Telnet and command-line commands, but there is no standard for that.

However I recommend you don't do that. Exposing your private network to access by the outside world needs to be done in such a way as to preserve your network's security. You obviously aren't able to do that, or even to ask the right questions about it, so I would recommend you just forget the idea.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
okay..
but can i start to read about this??
how and from where??
that makes me to start it again but later.

Thank you
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Punit Jain wrote:okay..
but can i start to read about this??
how and from where??
that makes me to start it again but later.

Thank you


As I've already pointed out, you're not really in the right place to learn about port forwarding.

Did you read the Wikipedia article I linked? (May have been in your other thread, I don't recall.)

Did you try googling for more information on port forwarding?

Did you try doing any research on network security?

Did you try looking at your router's documentation, which has been mentioned twice so far?

And finally, take a step back: What are you actually trying to accomplish, and for what purpose?
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2

Did you read the Wikipedia article I linked? (May have been in your other thread, I don't recall.)

yes i read this, but this saying the concept of port forwarding only, not much..

Did you try googling for more information on port forwarding?

yes i did, and i got how to do port forwarding in my router.

Did you try doing any research on network security?

no i didn't try. this is also i want to know, from where i should start??

And finally, take a step back: What are you actually trying to accomplish, and for what purpose?

i m trying to creating a chat application, in which if i want to communicate any machine, which is connected to internet or lan, i just need to install my client files/installer, and i will be able to communicate with that machine.(not only with a single machine, any machine which is connected to the internet or lan).

one more thing i am new in networking.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19070
    
  40

Punit Jain wrote:

Did you read the Wikipedia article I linked? (May have been in your other thread, I don't recall.)

yes i read this, but this saying the concept of port forwarding only, not much..


There really isn't much to it -- the router is configured to accept and connect a request on a port -- and forward that request to another machine within the private network (and use the same or different port).

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2

the router is configured to accept and connect a request on a port -- to another machine within the private network (and use the same or different port).

you mean to say i need to assign a port in my router configuration in port forwarding, and i also need to assign the same to others router, whom i want to connect??
i mean i assign a port number in my router and also give the server ip address, and the same thing i need to do in others router, isn't it??
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1031
    
    5

i just need to install my client files/installer, and i will be able to communicate with that machine.


Things are not that simple. Regardless of your software or any other application, the machines you wish to communicate with each other need to be configured to enable this access.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
i apologies for posting this question in wrong forum, also for asking silly question, although i am new to networking.
but can you tell me is it possible that if i install my client application, the machines i wish to communicate will automatically configured and enable communication..
i am sorry if i asking silly things.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Punit Jain wrote:
i m trying to creating a chat application,


Why? For educational purposes, or other?

in which if i want to communicate any machine, which is connected to internet or lan, i just need to install my client files/installer, and i will be able to communicate with that machine.(not only with a single machine, any machine which is connected to the internet or lan).


There are a couple different possible interpretations of that, and for one of them the answer is that it's impossible.

In brief, though, if you want machine A and machine B to communicate, then either 1) At least one of those machines has to have a public IP address or be receiving port forwarding from its router, or 2) There has to be a machine C that is reachable by a public IP or by port forwarding.

So you need to decide which architecture you want--pure peer-to-peer, or relay server. And regardless of which approach you choose, you'll need at least one machine that is publicly reachable.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2

Why? For educational purposes, or other?

yes actually in this semester i got some part of java networking in my java syllabus, so i m trying to implement it, and trying to learn more.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Punit Jain wrote:
you mean to say i need to assign a port in my router configuration in port forwarding, and i also need to assign the same to others router, whom i want to connect??
i mean i assign a port number in my router and also give the server ip address, and the same thing i need to do in others router, isn't it??


Yes, one approach is that everybody who will be communicating with this app configures their router for the appropriate port forwarding. That's not a realistic approach for anything more than a few friends just messing around.

And when you say, "I also need to assign the same to others' routers", what really happens is that you ask them to configure their routers to forward router port X to port Y on the machine that's running your app. It's up to them whether they actually want to do that or not. I certainly wouldn't use an app that required me to do it.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Punit Jain wrote:

Why? For educational purposes, or other?

yes actually in this semester i got some part of java networking in my java syllabus, so i m trying to implement it, and trying to learn more.


Okay, so then all you need is to set up your own machine as a server (but be careful when configuring your router), and tell your friends about it so they can connect to you.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2

so then all you need is to set up your own machine as a server (but be careful when configuring your router), and tell your friends about it so they can connect to you.

okay this i can do now.

And when you say, "I also need to assign the same to others' routers", what really happens is that you ask them to configure their routers to forward router port X to port Y on the machine that's running your app. It's up to them whether they actually want to do that or not. I certainly wouldn't use an app that required me to do it.

so what you would use??

So you need to decide which architecture you want--pure peer-to-peer, or relay server. And regardless of which approach you choose, you'll need at least one machine that is publicly reachable.

okay i will read about both of the architectures.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Punit Jain wrote:
Jeff Verdegan wrote:
And when you say, "I also need to assign the same to others' routers", what really happens is that you ask them to configure their routers to forward router port X to port Y on the machine that's running your app. It's up to them whether they actually want to do that or not. I certainly wouldn't use an app that required me to do it.

so what you would use??


If I'm using an app where I communicate with another computer, it has to be an app where I initiate the connection from my computer to the server. What you're talking about here is that your users have to let their computers operate as the server to receive connection requests. This is both insecure and inconvenient.

Do you ever use Skype, or AOL Instant Messenger, or GoogleTalk, or Yahoo Messenger? None of those have you opening a connection to the computer of the person you're talking to.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2

Do you ever use Skype, or AOL Instant Messenger, or GoogleTalk, or Yahoo Messenger? None of those have you opening a connection to the computer of the person you're talking to.


yes actually i was asking, how the will do??
i mean how they are designed or developed??
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Punit Jain wrote:

Do you ever use Skype, or AOL Instant Messenger, or GoogleTalk, or Yahoo Messenger? None of those have you opening a connection to the computer of the person you're talking to.


yes actually i was asking, how the will do??
i mean how they are designed or developed??


That question is far too broad and vague to be answered in a forum. For the part that's relevant to this thread though, they use a central server. Participants connect to that server, and it relays messages between them.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
okay, one last thing.
Okay, so then all you need is to set up your own machine as a server (but be careful when configuring your router), and tell your friends about it so they can connect to you.


is this the only thing which i can do now?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Punit Jain wrote:okay, one last thing.
Okay, so then all you need is to set up your own machine as a server (but be careful when configuring your router), and tell your friends about it so they can connect to you.


is this the only thing which i can do now?


Well, think about it.

If you've been paying attention to your own thread, you already know that you have to put your server on some machine that has a public IP or that you can port forward to. Do you have access to any other machine that meets this requirement?
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2

Do you have access to any other machine that meets this requirement?


no, i have four machines connected to same network, but all have private ip, but my network ip is public.
but all systems(4 machines) that are connected to the routers have private ip's.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Punit Jain wrote:

Do you have access to any other machine that meets this requirement?


no, i have four machines connected to same network, but all have private ip, but my network ip is public.
but all systems(4 machines) that are connected to the routers have private ip's.


Then you have your answer.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
i am little bit confuse here.
can i take my networks ip address, although it's public.
right now i am taking my machine ip address that is private.
so instead of this can i take my router ip?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Punit Jain wrote:i am little bit confuse here.
can i take my networks ip address, although it's public.
right now i am taking my machine ip address that is private.
so instead of this can i take my router ip?


If you want to allow somebody from outside world to connect to a server running on your network, and that server has no public IP address, then you set up your router to port-forward to your server, and the outside world connects to your router's public IP address (if it has one--if not, you're out of luck).

How many more times and in how many more ways does this need to be said?

Punit Jain wrote:
Jeff Verdegan wrote:
so then all you need is to set up your own machine as a server (but be careful when configuring your router), and tell your friends about it so they can connect to you.

okay this i can do now.


I thought you understood back at that point.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
yes i got it..
thank you very much for a great explanation..
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19070
    
  40

Jeff Verdegan wrote:If I'm using an app where I communicate with another computer, it has to be an app where I initiate the connection from my computer to the server. What you're talking about here is that your users have to let their computers operate as the server to receive connection requests. This is both insecure and inconvenient.

Do you ever use Skype, or AOL Instant Messenger, or GoogleTalk, or Yahoo Messenger? None of those have you opening a connection to the computer of the person you're talking to.



I know that this opens a new can of worms -- but just to be complete. Most professional chat systems actually have multiple ways to connect. For the most part it does use a centralize server -- but if the server deems that the two endpoints can connect directly, sometimes they do.

Also, some of these chat systems check to see if the router support (and have enabled) UPnP -- and if do, will request that the router do a port forward programmatically.

Henry

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2

Also, some of these chat systems check to see if the router support (and have enabled) UPnP -- and if do, will request that the router do a port forward programmatically.


you mean to say i have to first listen to that port by opening server socket, and than i have to write into that, using socket. isn't it??
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Punit Jain wrote:

Also, some of these chat systems check to see if the router support (and have enabled) UPnP -- and if do, will request that the router do a port forward programmatically.


you mean to say i have to first listen to that port by opening server socket, and than i have to write into that, using socket. isn't it??


No, it's not that simple. When you see a new term like UPnP, rather than asking the forum how it works, it's time for you to do off and do some research on your own. However, before you even attempt anything like UPnP, I strongly urge you to first take the smaller, simpler step of getting it working by manually setting up port forwarding. Otherwise, you'll be trying to tackle too many new things at once, and when something doesn't work, you won't know where to look.

This is good advice that applies to all development projects: Work on one thing at a time, and get the simple parts working before adding more complexity.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19070
    
  40

Punit Jain wrote:

Also, some of these chat systems check to see if the router support (and have enabled) UPnP -- and if do, will request that the router do a port forward programmatically.


you mean to say i have to first listen to that port by opening server socket, and than i have to write into that, using socket. isn't it??



Nope. UPnP is a completely separate channel / connection (and protocol) between your application and your router. I have never done it myself, so can't help you.

Sorry,
Henry
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19070
    
  40

Jeff Verdegan wrote:No, it's not that simple. When you see a new term like UPnP, rather than asking the forum how it works, it's time for you to do off and do some research on your own. However, before you even attempt anything like UPnP, I strongly urge you to first take the smaller, simpler step of getting it working by manually setting up port forwarding. Otherwise, you'll be trying to tackle too many new things at once, and when something doesn't work, you won't know where to look.

This is good advice that applies to all development projects: Work on one thing at a time, and get the simple parts working before adding more complexity.



I'll go one step further. It may be a good idea to see if your router supports (and is setup for) UPnP -- otherwise, everything is moot.

Henry
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
yes i just checked, my router supports UPnP..
okay i m going to o some research..
can you suggest me something to read, as a beginner?

Thank You..

Roger Sterling
Ranch Hand

Joined: Apr 06, 2012
Posts: 426

Punit Jain wrote:yes i just checked, my router supports UPnP..
okay i m going to o some research..
can you suggest me something to read, as a beginner?

Thank You..



Try this manual:

http://www.cisco.com/application/pdf/paws/13769/5.pdf

It explains how routers work and the tasks you are asking about.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
Thank you.....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to do port forwarding in java?