File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Socket connection program works for localhost but not for other ip Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Socket connection program works for localhost but not for other ip" Watch "Socket connection program works for localhost but not for other ip" New topic
Author

Socket connection program works for localhost but not for other ip

Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

Hi all, I have one socket connection program as
// For server



//for client



when I run this program it create connection and send and data from server successfully. But when I use other machine IP as

Socket sock = new Socket("10.22.35.32",13267);

then on client machine it shows error as connection time-out. and there is no connection established between server and client. Why is it so? I started server program on one pc and run client program from another pc.


Life is easy because we write the source code.....
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

When I interchange client and server then it works perfectly. But not work for other combination why is it so?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

Sounds like a networking issue. Make sure you can ping the server machine from the client machine. If that works use telnet to check if you can connect to it: If that already fails then something is blocking access, probably a firewall either on the server machine, on the client machine or on a router between the two.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

Thanks Rob for response. Yes because of firewall it is blocking access.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

Then you need to add exceptions to the firewall, to allow this traffic.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Socket connection program works for localhost but not for other ip