Calling setsockopt to allow reuse of socket.

This commit is contained in:
Michael Jumper 2011-01-21 10:01:49 -08:00
parent e45c8be4da
commit 55f5755fc3

View File

@ -75,6 +75,7 @@ int main(int argc, char* argv[]) {
/* Server */
int socket_fd;
struct sockaddr_in server_addr;
int opt_on = 1;
/* Client */
struct sockaddr_in client_addr;
@ -116,6 +117,10 @@ int main(int argc, char* argv[]) {
exit(EXIT_FAILURE);
}
if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &opt_on, sizeof(opt_on))) {
fprintf(stderr, "Warning: Unable to set socket options for reuse: %s\n", strerror(errno));
}
/* Bind socket to address */
if (bind(socket_fd, (struct sockaddr*) &server_addr,
sizeof(server_addr)) < 0) {