File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

connect two comps with socket newbie Q

 
Kieth Nogins
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This sounds like a fairly simple problem but I think I did'nt quite grasp the idea of sockets.
I want to run a java program on one computer that listens for connections using a ServerSocket:


and I want another computer to run a client program that connects to this computer using a socket:


What do I write instead of the ... ? Do I write the IP address? Is this process even possible?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you're starting to get the right pieces together. The client would use the server's IP or machine name on a network or DNS name in the world. The Sun Networking Tutorial ought to have exactly what you want to know. Type in the echo server examples and see how close they are to what you've figured out.
 
Kieth Nogins
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you stan,
The examples (and the short program that I wrote) work well when I run the client and the server on one computer and I use either "localhost" or "127.0.0.1".
But when I tried to run the server on one computer and the client on a totally remote computer, I connected using the ip obtained from: www.whatsmyipaddress.com , I get a: Connection Refused error.
Could there maybe be a windows xp setting that allows connections to enter? I tried also disabling the antiviruses on both sides.
 
Paul Clapham
Sheriff
Pie
Posts: 20206
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start by working with two computers in the same network. Otherwise you have to deal with networking issues that will just distract you from what you are doing.
 
Kieth Nogins
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Paul Clapham, I did start on a small network and everything works fine. But, when I run the applications on totally remote computers, the socket returned a Connection Refused error. ???
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to have a network route between the two computers. Are there firewalls configured on the computers? Are there routers or proxies between them? Can you ping the computers from each other?
 
Kieth Nogins
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are routers on both sides but the pings were succesful.
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's good. At least you have a network route.
How about firewalls? You have to make sure they are not blocking port 8090 (or whatever port you are using) on the server side. If you are using something like Zone Alarm, which blocks outgoing connections, you'll have to tell it to let traffic out.
By 'routers' do you mean DSL routers or other internet-connection sharing devices? The "server" side will have to be configured to forward the traffic to your "server". Have a look this site for info on that.
 
Kieth Nogins
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe Ess ,
The port forwarding article really helped. I configured my router to forward all packets to port 8090 to the server computer and everything worked smoothly from there.
thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic