tags:

views:

1138

answers:

5

Java Socket Program did not work for WAN

I have written a TCP IP socket program which works fine in my LAN. One of my friend is at bangalore He ran the server and I ran the client with the host name of my friend's IP. In this case my socket program did not work.

+2  A: 

Your friend running the server is most likely behind either a firewall or NAT. Make sure you are using the external IP address and if necessary port forwarding the packets to the correct IP.

Jeff T
Thanks Jeff T,How can I detect that my friend is behind firewall or NAT. If this is the case so how to overcome from this issue. My friend told me he is not behind firewall.How to write socket programming in java to overcome these issue.
A: 

You could use an implementation of STUNT or other NAT Traversal protocol.

macbirdie
Thanks Macbirdie,How to use STUNT or NAT Traversal protocol for TCP IP socket programming in java.
You need to learn the basic principle behind those protocols and apply it in your applications, either by using an off-the-shelf library or creating your own code.
macbirdie
+4  A: 

You said that your program is attempting to connect to host 192.168.1.107 port 46216.

192 prefix specifies it is a class C address and is private. Making your program connect to that will force it to remain on the local network searching for that node. You will need to find the IP address of your router (you can use http://whatismyip.org/ to find this out). Then go into your router settings and forward port 46216 to 192.168.1.107 (your node), or even better, your MAC address which is not subject to change (in case your router is running DHCP).

on a side note, it isn't good to hardcode IP addresses. Simply use a textfield to avoid having to redistribute the client when your IP is changed, as it is likely you have a dynamic IP from your ISP.

John T
A: 

first open the port in the server. so that ur frnd can connect with u

Deepak
May I know the reason of negative comments
Deepak
+1  A: 

The IP address you gave seems to be a local address, rather than a public internet address. If you are looking for 192.x.x.x, you will not make it out to "the internet", but will be confined behind your router.

WhatIsMyIP is a good way of getting a public IP address, and THAT is the address you should use in your connection. Also, be sure to forward any ports that will be used by your program, because otherwise your router will likely filter the traffic and still create an issue.

Matt D