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");
exit(1);
}
When I run the program for the first time, it works fine but when I run it the second time, I get this error:
I think when I run the program second time, it gives this error because the port was already linked to program which I run the first time. Can someone tell me how to close the port currently in use? Or suggest me something else which can solve this error.