This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a created a TCPClient class to handle the socket programming on the client side. The server is a device that I intend to send messages to execute various commands. Under this class I have constructed a client socket with the server's host name and port no. Running the program throws UnknownHostException. I have verified I am using the correct device name. i knew this after I checked on my router's configuration page where a list of connected devices were displayed.
But when I use an InetAddress object containing the server's IP address, I get no errors and the connection is successful. This however brings a huge limitation in that, I have to enter the IP address every time since the device's (server) DHCP is enabled. What could be the problem?
Sounds like there's nothing present to resolve that name, which is not a Java issue. The fact that the name shows up in your router's config table doesn't necessarily mean anything. That may just be the name that that host is reporting to the router, but that doesn't mean the router will act as a resolver for that name.
From a command line if you do ping hostname or telnet hostname, what result to do you get? If you get something like "unknown host", then it's definitely not a Java issue. If this is just a host on your LAN and its IP address won't change, you can add an entry for it in your hosts file. On Linux it's /etc/hosts and on Windows it's something like C:/Windows/System32/drivers/etc/hosts.
Joined: Feb 16, 2012
I think its definitely not a java issue becoz I am getting this erro; "Ping request could not find host Wifly GSX. Please check the name and try again."
Joined: Feb 16, 2012
Since I know the host Ip address is there a way I can use it to get its hostname?. I know am going out of topic but I would appreciate any help on this.
abdy hussein wrote:Since I know the host Ip address is there a way I can use it to get its hostname?.
That doesn't really make any sense.
If you know the IP address, you can just use that to connect.
If you want to use the host name instead of the IP (a better approach, when feasible), then either have your network admins put an entry in whatever naming service you're using, or else add an entry to your /etc/hosts or C:/Windows/System32/drivers/etc/hosts. (If you do the latter, then you'll of course have to update it each time the IP address changes.)
Note also that the hostname that maps to an IP address doesn't have to be the same as what the computer thinks its own name is (i.e., what you get as a result of the hostname command on that computer).