• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to do port forwarding in java?

 
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your Java code never knows anything about any port forwarding that's going on. It's strictly a router configuration issue.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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: https://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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no actually, i m asking any resource for port forwarding??
that tells me how to do everything, you said..
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Punit Jain
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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??
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes i got it..
thank you very much for a great explanation..
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..

 
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.....
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic