Handling improper Client Disconnects
Posted: Tue Mar 16, 2010 12:04 pm
I've been meaning to ask this question for a while and someone posted a question that is in some ways just the opposite of the problem I'm trying to deal with so...
The NB board acts as the server and only ever wants to allow one client to connect and control it at a time. The first problem I have is that you can't specify 0 to mean no one can queue on the listen port. The minimum value is 1 and that means one client can connect and one can queue. The second and more important problem is the strategy for dealing with clients that don't properly close their connection. That is, they just crash or something similar so that the NB Tcp server has no way of knowing they are gone. Here are two things I have tried.
1. Do an intermittent ping to make sure the client is still there. PROBLEM: Some clients may not respond to pings, it puts additional noise traffic on the network and worst of all, if the client is another embedded system that can crash/reboot within a couple of seconds then the ping interval has to be way too fast. No network admin wants a device on their network that sends out a ping every second.
2. Set up second listen port on a separate port. When any connection comes in on that port it tells the NB to force close the existing connection with the client. This seems to work OK but requires a little more work for the client than I would like and has the potential for abuse. In reality I haven't seen the abuse but most of the systems are on closed networks with well-behaved engineers. The client software just needs to know about the possibility of getting locked out and know to connect to the special port first, to clear the old connection and then connect to the normal port. Of course on the NB side it also requires an extra task to monitor the special port.
I noticed from answers to the other post that several folks seem to know a great deal more about this situation than I do and I'm hoping someone might have a better solution.
Tod
The NB board acts as the server and only ever wants to allow one client to connect and control it at a time. The first problem I have is that you can't specify 0 to mean no one can queue on the listen port. The minimum value is 1 and that means one client can connect and one can queue. The second and more important problem is the strategy for dealing with clients that don't properly close their connection. That is, they just crash or something similar so that the NB Tcp server has no way of knowing they are gone. Here are two things I have tried.
1. Do an intermittent ping to make sure the client is still there. PROBLEM: Some clients may not respond to pings, it puts additional noise traffic on the network and worst of all, if the client is another embedded system that can crash/reboot within a couple of seconds then the ping interval has to be way too fast. No network admin wants a device on their network that sends out a ping every second.
2. Set up second listen port on a separate port. When any connection comes in on that port it tells the NB to force close the existing connection with the client. This seems to work OK but requires a little more work for the client than I would like and has the potential for abuse. In reality I haven't seen the abuse but most of the systems are on closed networks with well-behaved engineers. The client software just needs to know about the possibility of getting locked out and know to connect to the special port first, to clear the old connection and then connect to the normal port. Of course on the NB side it also requires an extra task to monitor the special port.
I noticed from answers to the other post that several folks seem to know a great deal more about this situation than I do and I'm hoping someone might have a better solution.
Tod