• 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

Connecting to server using its host name

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

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?

Here is the code.



Thanks.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
abdy hussein
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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."

Thanks.
 
abdy hussein
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Thanks.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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).


 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I was wondering whether you have managed to find a solution as I have exactly the same problem.

I am writing an Android app to link to a WiFly module.

The problem is that the ip address assigned to the WiFly by my router can change thus making it impossible to to know where to connect to at the Android end.

Thanks

Ian James
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic