add reuseaddr
This commit is contained in:
parent
d5f1fafd0b
commit
2880b0791e
7
server.c
7
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);
|
||||
|
Loading…
Reference in New Issue
Block a user