This question has been asked before, yet I just can\'t seem to come to grips with it as small details of all the questions ive ever seen throw me off...
I keep having is
The socket can linger in a TIME_WAIT state for a while after being closed. To be able to reuse a socket while in this state set SO_REUSEADDR
Yes, the relevant socket option is called SO_REUSEADDR. You use setsockopt() to set socket options.
You should normally not close the server's main socket though, instead you should use accept() to create per-client sockets, which can be closed when the client disconnects.