Hi there,
I have my Arduino connecting to my PC via a TCP socket (that means I use EthernetClient in Arduino to connect to a java ServerSocket on my PC).
But if I try to reset Arduino (by pressing the button) or removing the power, the java program does not detect that the connection is broken.
Is there a way to work-around this?
Is there a way to work-around this?
Send heartbeat messages. This means you define some command in your protocol that does nothing except resetting a timer. If the timer reaches some configured value your connection is dead and can be closed.
Broken connections are always detected that way because if you switch off your laptop (not by software but by disconnecting power and battery) your connection will stay alive too because no packet with FIN bit is sent.
The Java program should have a timeout on the tcp connection like a browser does. If the connection breaks, there is nothing sent, so the connection will stay open. I use 10 seconds on my ethernet shield timeout.