add reuseaddr

This commit is contained in:
ubuntu201711081 2020-12-03 23:16:51 +00:00
parent d5f1fafd0b
commit 2880b0791e

View File

@ -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);