diff --git a/server.c b/server.c index e8e90ee..964804c 100644 --- a/server.c +++ b/server.c @@ -136,12 +136,17 @@ int main(int argc, const char *argv[]){ fprintf(stderr,"port invalid"); return 1; } - sock = socket(AF_INET,SOCK_STREAM,0); if(sock < 0){ perror("sock create fail"); return 1; } + { + int option = 1; + if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&option,sizeof(option)) < 0){ + perror("setsockopt"); + } + } addr.sin_addr.s_addr = inet_addr(server_name); addr.sin_family = AF_INET; addr.sin_port = htons(server_port);