• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to check if connection is still good

 
Cliff Smith
Greenhorn
Posts: 3
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Any ideas?

Thank you,
Cliff Smith
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about asking for the current folder using pwd? The results won't be long and it's sure to give you back something.
 
Cliff Smith
Greenhorn
Posts: 3
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob,
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.
Any ideas?

Cliff Smith
 
Cliff Smith
Greenhorn
Posts: 3
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic