On 1/14/06, Albert
Hi
I've got a server that runs a custom daemon listening on port 4010 outputting data received from a data logger on a RS232 port. This has now been running for 3 months. Every now and again there is some invalid data from the data logger on the RS232 port which causes an exception to be raised, the daemon is stopped and then restarted. It then binds to port 4010 again and continues as normal.
Today I was unable to connect to port 4010. The daemon could not even bind to port 4010. When changing the port to port 4020 or 4015 it worked without a problem, but changing back to port 4010 it was not possible to bind to port 4010.
I did the following in order to try getting it back on: - stopped the daemon for about 10 minutes before starting it again - closed the port in the SuSE firewall to make sure there are no clients who are trying to connect on the port.
None of this worked. I had to reboot the machine to get it working again.
Have anyone heard of this or know what it could be?
Albert,
what you experience here is that the TCP/IP stack does not allow a
port to be re-used immediately by default. There is a timeout (of
unknown length, to me at least) which prevents applications to re-bind
to that port immediately. Consider using the SO_REUSEADDR socket
option before calling bind() to circumvent this "limitation". The
disadvantage is that it allows other applications to bind to the same
port at the same time (yes, sounds odd), but only one app will serve a
client. You will have to do extra checking to prevent this if you're
running multiple instances of the server process.
\Steve
--
Steve Graegert