• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem connecting to "localhost"

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 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
reply
    Bookmark Topic Watch Topic
  • New Topic