I am trying to write a basic server socket program. I use the following code to bind the server socket.
/* Bind the server socket */
if (bind(serversock, (struct sockaddr *) &server, sizeof(server)) < 0)
perror("Failed to bind the server socket");
Kill the process that binds the port:
fuser -TERM 80/tcp #kills processes on tcp port 80 using signal SIGTERM
and start again.
TCP sockets normally aren't reusable for a while (a few minutes), unless they had the
SO_REUSEADDR option set (with
setsockopt) before they were bound.
(This option somewhat decreases robustness, but should be fairly safe to use in a testing environment.)