| Author |
Sending commands to a remote server
|
abdy hussein
Greenhorn
Joined: Feb 16, 2012
Posts: 10
|
|
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
Joined: Mar 22, 2000
Posts: 12324
|
|
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
|
Java Resources at www.wbrogden.com
|
 |
abdy hussein
Greenhorn
Joined: Feb 16, 2012
Posts: 10
|
|
|
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
Joined: Mar 22, 2000
Posts: 12324
|
|
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
Joined: Feb 16, 2012
Posts: 10
|
|
Hi william thanks for the suggestion....I was able to connect to the device and send commands.
I really appreciate your help...
|
 |
 |
|
|
subject: Sending commands to a remote server
|
|
|