• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Problem connecting to "localhost"  RSS feed

Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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, 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?


How do they get the deer to cross at the signs? Or to read this tiny ad?
global solutions you can do at home or in your backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!