Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sending commands to a remote server

 
abdy hussein
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I recently embarked on a project involving controlling a microcontroller remotely using wifi. Commands are sent from a windows app to a wifly shield which passes them to the mcu. The wifly shield and the computer are on the same adhoc network and i was able to ping and telnet between them successfully. The problem arises when the app throws an unknownHostException after sending the commands. I checked the ports and host name clearly and everything is ok. The app is the client while the wifly shield is the server and at the time of sending the commands the shield is up and running. Here is the TCPClient class that the app uses.



Here is the event handling part that uses the TCPClient class



Hope to find some help over here. Thanks.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since UnknownHostException is thrown by the java.net.InetAddress.getByName() method:

InetAddress address = InetAddress.getByName(host);

Your code in sendMessage is not getting past that statement in line 23, no connection is made and no commands sent.

Clearly the host name is not "ok" and the statement that uses the port is never reached.

Bill
 
abdy hussein
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The host name is ok as I got this from my router's configuration page before I switched to adhoc mode. I tried to change the port number but same result. could this be something to do with the adhoc mode as I am not familiar with it?....
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the host name was "ok" then the getByName() would be able to look it up and would not be throwing the UnknownHostException.

If you can get an IP address, why not use the getByAddress( byte[] ) method to create an InetAddress.

Bill







 
abdy hussein
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi william thanks for the suggestion....I was able to connect to the device and send commands.

I really appreciate your help...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic