Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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 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
 
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!