Skip to main content

Can't get remote host name when running on OS X

No replies
Joined: 2012-07-30

I'm fairly new at Java and new with Sockets. I'm in the final stage of testing a package that provides communication of message objects between a master computer and clients. I've been working in LINUX but have only one machine available to act as a client and wanted to see if the master could actually handle more than one client so I brought my mac Air in and hooked it up. It mostly works but the Air cannot get the host name of the remote master, what is returned is the IP address which it already knows. The machines are all behind the same router. When deployed they will be behind the same router or switch on a tiny LAN on an aircraft.

This is quite perplexing to me...

Here's my code, no exception is caught:

public static String getRemoteName(Socket socket) {
  String hostName = "";
  try {
InetAddress machine = socket.getInetAddress();
hostName = machine.getHostName();
int pos = hostName.indexOf(".local");
if (pos > 0)
   hostName = hostName.substring(0, pos);
} catch (SecurityException e) {
   // do something

return hostName;