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 written an app that monitors multiple external devices (serial to ethernet converters spread over a wide geographic area). Everything is working except I can't tell if a connection drops (remote box down, power out, mice chewed through cable, somebody kicked the plug out, etc.)
I am using telnet protocol from the jakarta.commons.net.telnet (?) package.
Each remote device is monitored in a seperate thread and the whole thing runs as a service on a linux machine.
I can add code to periodically check something, but what?
Thanks for your reply.
On my end I am running what amounts to a passive listening service once the connection has been established. The serial ports that are being monitored remotely are not communication ports to any type of system in the normal sense (linux, windows, rtos). About the only remote commands they respond to are reboot and reset to factory defaults.
Once the connection is established, there is a 'keep-alive' issued by the remote device over the ip port every 45 seconds, but I can't figure out a way to check from within the thread if the connection is still 'live'.
If I understand it correctly, 'telnet.isConnected', for example, only tells me if a connection was established initially but not if it is still active at a later time.
I think I figured out a work-around. The remote units seem to always respond to any input with an <ACK/>. It appears that if it is an invalid command they still return the <ACK/> but otherwise ignore the message. So what I do is send what would be an invalid command, like just a space (0x20). If no response, then the connection has been lost and the appropriate measures taken. If I get a response the connection is still good.
Unfortunately, this is specific to these devices and not something within Java itself, but it works for my needs.