Calling setsockopt to allow reuse of socket.
This commit is contained in:
parent
e45c8be4da
commit
55f5755fc3
@ -75,6 +75,7 @@ int main(int argc, char* argv[]) {
|
|||||||
/* Server */
|
/* Server */
|
||||||
int socket_fd;
|
int socket_fd;
|
||||||
struct sockaddr_in server_addr;
|
struct sockaddr_in server_addr;
|
||||||
|
int opt_on = 1;
|
||||||
|
|
||||||
/* Client */
|
/* Client */
|
||||||
struct sockaddr_in client_addr;
|
struct sockaddr_in client_addr;
|
||||||
@ -116,6 +117,10 @@ int main(int argc, char* argv[]) {
|
|||||||
exit(EXIT_FAILURE);
|
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 */
|
/* Bind socket to address */
|
||||||
if (bind(socket_fd, (struct sockaddr*) &server_addr,
|
if (bind(socket_fd, (struct sockaddr*) &server_addr,
|
||||||
sizeof(server_addr)) < 0) {
|
sizeof(server_addr)) < 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user