From 2880b0791e5eb5e0517ed9ea67a7160cff9dcd19 Mon Sep 17 00:00:00 2001 From: ubuntu201711081 <201711081@jbnu.ac.kr> Date: Thu, 3 Dec 2020 23:16:51 +0000 Subject: [PATCH] add reuseaddr --- server.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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);