File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Problem connecting to Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "Problem connecting to "localhost"" Watch "Problem connecting to "localhost"" New topic
Author

Problem connecting to "localhost"

Robert Miller
Ranch Hand

Joined: Jun 18, 2004
Posts: 56
I'm working with a Java application that uses Socket objects for communication and I'm seeing something strange, that I hope someone can help me with.

The system consists of a process that listens for connections from other processes. The client processes create a Socket object and bind it to a specific port number so that the server process can identify the client on connection. The code looks like this:



This code works fine if hostname is not set to "localhost". If it is set to any hostname on the system, or any IP address (including 127.0.0.1), it works. If it is set to "localhost" the connect() call gets a ConnectionRefused exception.

If the bind() call is commented out, then the code always works even if hostname is set to "localhost", but then the server process can't identify the client on connection.

Does anyone know why this code is failing and what I can do to fix it?

Thanks,

Robert
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Problem connecting to "localhost"
 
Similar Threads
setting socket traffic class option on linux
Problem in proxy settings
Need a simple Java LDAP client
retrieve images from the web
How to find a port is free or not without catching any Exception ?