• 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

can we use ServerSocket and Socket for Wide area network?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
cross posted http://forums.oracle.com/forums/message.jspa?messageID=9743986#9743986

Hi im not sure if this is the right place to post this question. you know guys ServerSocket and Socket is very common in networking because it is always use in local area network and my question is can we use ServerSocket and Socket for wide area network? if not what is the code to achieve wide area network using java?

i ask this because i use ServerSocket and Socket in local-area network and now i want to connect my computer to a long distance example my computer is in the country Philippines and my friends computer is in USA how to connect them like client server?

is this possible using ServerSocket and Socket? if not what are the code to achieve that?

im asking this because i want to create chat application like what i did using ServerSocket and Socket in local-area network.
then now i want to create chat application in wide area network but i dont know how. plss.. suggest.
 
Sheriff
Posts: 22783
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
ServerSocket and Socket have no limitations of their own for their connectivity, so yes, you can use ServerSocket and Socket for the WAN. However, you will need to configure your firewall / router to allow traffic from the WAN to the machine with the ServerSocket on that specific port. Otherwise the firewall / router will block the connections.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'd be using the same classes. The principal difficulty will be to make a network connection to the target machine. If it's your friend's home machine, he can just open his firewall on the port you intend to use. But if he's on a larger network (like a company network), incoming traffic will be blocked.

Which is pretty much what Rob Said, I now see...
 
Jhovarie Guiang
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi in local area network this is working

//server
ServerSocket ss = new ServerSocket(2346);

//client
String hostname = "PCNaameHere";
Socket theSocket = new Socket(hostname, 2345);

then my question is some IP addresses are the same.
correct me if im wrong is IP addresses thesame with TCP IP? if not where to find IP addresses that is needed to use for WAN network.

what kind of IP address is needed?
on client side problem.
String hostname = "PCNaameHere"; //what should i put here.
Socket theSocket = new Socket(hostname, 2345);

i tried this code



then the output is

Net interface: lo
IP address: /127.0.0.1
Net interface: eth0
Net interface: eth1
IP address: /192.168.50.1
Net interface: ppp0
IP address: /10.157.10.50

is the last result "IP address: /10.157.10.50" is the ip address that is needed for
String hostname = "PCNaameHere"; //<-- is this IP address: 10.157.10.50 //< is this the ip that is needed?
Socket theSocket = new Socket(hostname, 2345);
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'd need the external IP, or WAN IP, of the server*. Your client socket then sends the request through the WAN to that IP address. At that end there are two options:
1) The server PC is directly connected with that IP address (which is usually less secure). The connection is made directly, unless the PC's firewall software blocks it.
2) There is a firewall / router (let's call it FW) connected with that IP address, and the server PC is connected to the FW. The FW needs to redirect the connection to the server PC. This is called port forwarding. You'll need to check out the FW manual for more information on how to do this.

Sometimes it's also possible to use a hostname for the server, but one needs to be configured using DNS. The hostname is actually little more than an alias for the IP address.


* You can use sites like http://www.whatsmyip.org/ to find out what the WAN IP is.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic