• 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

trying to connect to another ip adress

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm trying to write a chat program using sockets. I can send and read messages within my own home, set up a server and a client, and all our ip adresses start with: 192.168 etc. but now I want to send something to for example 82.121.121.121 and that place also has a router which gives every pc there an ip adress of someting like 192.168.1.1. does anyone know how I can solve this?
 
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
IP addresses in the range 192.168.* are private addresses. It can't be connected to from the internet. This is why your router and the other network uses these addresses. There is no way for a machine outside of a private network to directly connect to a machine inside a private network. However...

One option is to use port forwarding on the router. You can configure the target router to forward a port (and protocol) to a machine inside its private network. The source machine still doesn't connect to the target machine directly though -- instead it uses the IP address of the router, and a port that will be forwarded to the target machine.

Henry
 
T Tberg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and how can I find that port and use it with java? or do you mean the port to make a socket?
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to know the following for a successful port mapping:
- the (fixed) IP address of the local machine; check your network settigns
- the (fixed) port of your Java server; you can (and should) choose this yourself

Next step is to go to the web interface of your router. The following is a general procedure; check the manual of your router for more details.
- go to NAT, firewall or something similar
- specify the outside port; the easiest is to use the same one as your Java server is running
- specify the protocol as TCP, unless you are using DatagramServerSocket in which case you should use UDP
- specify the IP address of your local machine as the machine to route to
- specify the port of your Java server as the port to route to

In short, the rule could be something like this:
- forward TCP connection on port 12345 to port 12345 on 192.168.1.2

You should then be able to connect to the local machine through the Internet.
 
T Tberg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've done that, but now I'm getting this error: java.net.ConnectException: Connection refused: connect
I've asked someone about this and he says the error has nothing to do with my router or anything, but he doesn't know how to fix it...
anyone?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When Rob said to configure "your" router, he intended to say you should configure the router that is in front of the system you are trying to connect to. Sockets are two-way connections, so once you establish a connection to, say, a computer behind 82.121.121.121, it can talk back without any configuration on your side*. You do, however, have to drill through their routers and firewalls to a computer that will accept your connection.
All the error "java.net.ConnectException: Connection refused: connect" tells us is that somemachine along the way is hanging up the phone. That can be caused by a router, modem, firewall, remote server failure or some other problem along the way. We don't have enough information to be more specific than that. I'm not sure if you giving us all the IP addresses and ports along the way constitutes a security risk, but I know my sysadmin would not be happy with it.

* NOTE: some firewalls, for example, ZoneAlarm, can block outgoing connections, so you may need to do some configuration
 
T Tberg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i've written my own server, on ip adress 192.168.a.a, and when i'm trying to connect from a pc within my own netwerk, from ip adress 192.168.a.b it works. but now i'm trying to connect from my ip adress 192.168.a.b via my own network 82.121.121.121 to 192.168.a.a. i've got a router which forward port 3333 to the other thing that makes the signal wireless and that thing forwards it to my pc. so both the server and the client are wireless. hopes this helps a bit?
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Niels Tielenburg wrote:now i'm trying to connect from my ip adress 192.168.a.b via my own network 82.121.121.121 to 192.168.a.a.



Is 82.121.121.121 an incoming internet client or are you trying to bridge two separate subnets? I think we've been operating under the assumption that it's an incoming internet client.
 
T Tberg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've also tried to connect from outside my own house to the server, so I think both?
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please tell us the entire network structure involved? Something like this:
local machine: 192.168.1.x - local router: x.x.x.x - remote router: x.x.x.x - remote machine: 192.168.1.x

Because to me, it's not clear which router the 82.121.121.121 IP address belongs to.
 
T Tberg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
T Tberg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
because I use port 3333 I forward on the router everything with port 3333 to the wireless maker and that thing forwards everything with port 3333 to the server
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the client and server are in the same network, on the same side of the router? Then why would you need to go through the router?
 
T Tberg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
because that's one situation, another is that there is a computer on the other side of the router
 
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

Niels Tielenburg wrote:because that's one situation, another is that there is a computer on the other side of the router



You need to draw us the network that is *not* working. And you need to tell us who is making the connections. Is the client always connecting to the server? or does the server make a connection back to the client?

Henry
 
T Tberg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just want to make a connection from the "internet" to my server and I tried that by trying to connect my client via 82.121.121.121 to the server and that didn't workt. I also tried to connect to the server from an ip like 83.131.131.131 and that didn't work either
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What Henry asked for is a diagram like the one you provided before but with the complete, non-working, structure. The diagram you posted does not reflect the network structure that your initial problem is about.
 
T Tberg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my entire network structure:P
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In that diagram you should never need to go through the router. The client and server are in the same subnet that will be handled by the wireless router 192.168.50.1 and the router with Internet IP address 82.121.121.121 and local IP address 192.168.1.1 will not even be included in communication between the client and the server.
 
T Tberg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know that and that works, but i've also got a computer not in that network, in a complete different city, and I want that computer to connect to my server;)
 
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
The diagram isn't complete... What is the ip address of the wireless component? The 192.168.50.1 address is only the default gateway address for it, meaning that is the address that is used to get from the private network out.

But to get in from the internet. It needs an address on the 192.168.1.* subnet. And it is this address that is used to forward the port to from the router.

Henry
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Henry said, the diagram is not complete. You also need to include the remote site.

However, I think I know where the problem lies. Your "wireless maker" is a router as well, so you need to put a port forwarding rule on both that one and the other router on your side (192.168.1.1). You basically have NAT behind NAT, kind of like two toll booths right after each other. Both need to let your requests through, not just one.
 
T Tberg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I already tried that, when my client ( 192.168.50.101 ) wants to connect to the server via 82.121.121.121, the signal goes through the first router(192.168.50.1) to the second. that router sees that it uses port 3333 so it forwards it back to the router(192.168.50.1) that router sees again that it uses port 3333 so it forwards it to
the server(192.168.50.102). Or so in theory, it doesn't work here...
 
T Tberg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and the ip of the router is 192.168.1.10;)
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Niels Tielenburg wrote:I already tried that, when my client ( 192.168.50.101 ) wants to connect to the server via 82.121.121.121



How do you propose to get 192.168.50.101 to connect to 192.168.50.102 via 82.121.121.121 ? Does 82.121.121.121 expose some sort of proxy that 192.168.50.101 can use? I don't think the following is possible:

that router sees that it uses port 3333 so it forwards it back to the router(192.168.50.1)



Even if it is possible, it would not be a valid test of external connectivity as the traffic never leaves your internal subnet.
If you want to test connectivity from 82.121.121.121, you have to initiate the connection from 82.121.121.121 or use a proxy to send traffic through it.
 
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

Niels Tielenburg wrote:I already tried that, when my client ( 192.168.50.101 ) wants to connect to the server via 82.121.121.121, the signal goes through the first router(192.168.50.1) to the second. that router sees that it uses port 3333 so it forwards it back to the router(192.168.50.1) that router sees again that it uses port 3333 so it forwards it to
the server(192.168.50.102). Or so in theory, it doesn't work here...



Followed by....

Niels Tielenburg wrote:and the ip of the router is 192.168.1.10;)



Which means that your port forwarding is wrong... the router siting on 82.121.121.121 needs to forward the port 3333 to the second router at 192.168.1.10. The first router can't get to 192.168.50.1, as it is on the wrong private network.

Henry
 
T Tberg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I just tried that via a pc outside my network and I could connect to my server:D
thanks for your help;)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic