aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes connect two comps with socket newbie Q Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "connect two comps with socket newbie Q" Watch "connect two comps with socket newbie Q" New topic
Author

connect two comps with socket newbie Q

Kieth Nogins
Greenhorn

Joined: Mar 10, 2006
Posts: 18
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

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Kieth Nogins
Greenhorn

Joined: Mar 10, 2006
Posts: 18
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Mar 10, 2006
Posts: 18
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

Joined: Oct 29, 2001
Posts: 8908
    
    8

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?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Kieth Nogins
Greenhorn

Joined: Mar 10, 2006
Posts: 18
There are routers on both sides but the pings were succesful.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8908
    
    8

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

Joined: Mar 10, 2006
Posts: 18
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
 
subject: connect two comps with socket newbie Q