TCP/IP socket binding problem

I have what appears to be a unique socket problem, although admittedly my tcp/ip programming experience is relatively limited.

I have a AIX server process using TCP/IP berkely sockets, and a Windows (C#) process. The windows process takes input from a user and sends a message to the Unix process to perform a system call.

If I kill the Unix process prematurely (ctrl-c), sometimes that socket is left bound to the port and the client has no idea that the process is dead. When I do a netstat -a | grep port, as long as I have the windows process running the connection to that socket is in ESTABLISHED state, and if I kill the windows process it goes to LISTENING state. It can take several hours (sometimes longer) for this socket to die, and obviously I cannot rebind. I have tried the setsockopt() with SO_REUSEADDR set, but I am still unable to re-bind to that port.

I've noticed that this ONLY happens if I have sent a message from the windows process since starting that windows process. If I start the windows process, connect to the unix server process, but don't send any messages, then I can kill and restart the unix process all day without the port getting stuck. Once the port gets stuck, it doesn't matter if I close the Windows process or not, there is nothing I can do to rebind to that port.

Is it possible there is some kind of cross-platform IP implementation conflict causing this to happen? A coworker set up a client-server echo program which sends data back and forth while regularly killing and restarting the server process. He has no problems with this, but it is only run on the AIX machine.

Well, I'm not sure why this is happening, but I suggest you install a signal handler on your UNIX socket process. The signal handler will forcefully shut down any and all sockets upon receipt of a signal or at the program's exit. It could be that for some reason, normal program termination does not close those sockets.