sudha kar wrote: > Hi All, > I am using lwip raw api's on Threadx RTOS. Our requirement is we need to > start and stop tcp service on demand. > > Tcp service is a interface for the clients to access the low level > api's from the server. I am spawning a thread whenever user requests > for service start and killing whenever user requests for stop the > service, in that thread I wrote the code for the server. > > If I continously stop and start the service for about 2 hours and > parallely some 4 to 6 clients are continously trying to access the > server my bind is failing, from that point I couldn't able to start > the TCP service even though I enabled reuse port option. > > Can anybody tell me the problem. > Appreciate the help. > > -- > Regards > Sudhakara Rao Murala > Vedams Software Solutions.
Hi Sudhakara, When a server that has connected clients is killed, the port does not become available immediately. There is a time lag before it is available (typically known as the TIME_WAIT state or 2MSL wait state). If you run 'netstat -a' you will see your port in timed wait state. One brute-force method to solve the problem is to create the socket with the option 'SO_REUSEADDR'. However, the right approach would be to send a signal to the server and handle the signal to close the connections gracefully. Namita

