Results 1 to 2 of 2
Hi
I have made a simple TCP Server application,
in the usual way (socket(), bind(), listen(), accept()).
After the transactions are done, i terminate the
server nicely:
Code:
shutdown(iSock, SHUT_RDWR);
...
- 12-23-2009 #1Just Joined!
- Join Date
- Sep 2007
- Posts
- 18
TCP: how to completely close a listening socket [SOLVED]
Hi
I have made a simple TCP Server application,
in the usual way (socket(), bind(), listen(), accept()).
After the transactions are done, i terminate the
server nicely:But when i want to start the application again immediately,Code:shutdown(iSock, SHUT_RDWR); close(iSock);
i cannot use the same port number to bind my listening port to -
i get the error corresponding to "Address already in use".
Only about a minute after i stopped the application, the port
is free again.
Does anybody know how a listening port can be made available
again immediately? Is this possible at all?
Thank you
JodyLast edited by jody; 12-23-2009 at 10:00 AM. Reason: solved
- 12-23-2009 #2Just Joined!
- Join Date
- Sep 2007
- Posts
- 18
I have found the solution:
call
before calling bind() in the creation of the server socket.Code:int reuse = 1; setsockopt(iSock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(int));
Jody


Reply With Quote