changed socket options and removed infinite loop
This commit is contained in:
@@ -85,7 +85,12 @@ int main(int argc, char* argv[]) {
|
||||
perror("Server: socket");
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Allow reuse of socket despite binding */
|
||||
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes,
|
||||
sizeof(int)) == -1) {
|
||||
perror("setsockopt");
|
||||
exit(1);
|
||||
}
|
||||
/* Bind */
|
||||
if (bind(socketfd, servinfo->ai_addr, servinfo->ai_addrlen) == -1) {
|
||||
close(socketfd);
|
||||
@@ -109,13 +114,11 @@ int main(int argc, char* argv[]) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
sin_size = sizeof their_addr;
|
||||
printf("Waiting for connection...\n");
|
||||
confd = accept(socketfd, (struct sockaddr *)&their_addr, &sin_size);
|
||||
if (confd == -1) {
|
||||
perror("accept");
|
||||
continue;
|
||||
}
|
||||
inet_ntop(their_addr.ss_family,
|
||||
get_in_addr((struct sockaddr *)&their_addr),
|
||||
@@ -124,8 +127,6 @@ int main(int argc, char* argv[]) {
|
||||
printf("Getting chatty with %s\n", s);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
/* You're the client */
|
||||
/* Get remote info */
|
||||
@@ -168,10 +169,10 @@ int main(int argc, char* argv[]) {
|
||||
printf("Connected!\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
pthread_create(&input_thread, NULL, input, (void*) msg);
|
||||
|
||||
pthread_join(input_thread, NULL);
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user