Binding error when trying to reconnect to the same port after closing a socket.
Posted on 2004-10-19
Here it goes. I have two processes running: the client and the server.
The server opens up a control port and starts accepting connections (it only handles one connection at a time).
The client then opens up and connects to the server. When it does, it opens a data port (the client is the server of the data port) and starts to accept connections on that data port.
Then the client sends one of 4 commands to the server: get, put, list, or quit. Get gets a file, put puts a file, list lists all the files, and quit quits.
When the client sends the quit, the server closes that particular socket and the data socket, and goes back to accepting the next connection.
Now, my problem is that, if I quit (close the client), then reopen the client right away and try to connect to the server, I can't bind to the same port.
I realize there is some kind of UNIX time_out thing that protects the port for a while if the socket doesn't terminate right, but mine does (as far as I know - I close the socket and everything)
And even more strange, I only get binding errors if before I disconnect I do a "put" command... nothing happens if all I do is a "get" or "list"... does sending data in the client->server direction have anything to do with it?
I'd apreciate if someone could clear up my mind on this one.