codeplea/Hands-On-Network-Programming-with-C

Chapter 2: time_server.c

Opened this issue · 2 comments

Hi codeplea,

I realized the following behavior: The server closes after connection of the client browser. Closing the browser on the local maschine
leads to the strange state, that the server cannot bind to the 8080 port. This I observed on my local Debian machines.
Is there maybe something not released in the example code. After some time the binding is again possible. I think this is reasoned by TIME_WAIT for old packages. But it needs really minutes that the 8080 port is available again. Is there a way
to programmatically avoid this wait cycle. Maybe to early asked -- started the book reading some minutes ago.

Thanks for info, Stephan

Hi Stephan,

Have you read the sections in the book called "Connection tear-down", "The shutdown() function", and "Preventing address-in-use errors" starting on page 378 and? It sounds like a TIME-WAIT issue. You can diagnose with netstat -na. If that is indeed the issue, then the simple fix is to use the SO_REUSEADDR flag.