| Sign In/My Account | View Cart |
| Article: |
Networking and the BSD Sockets API | |
| Subject: | Address in use | |
| Date: | 2002-12-28 22:24:50 | |
| From: | jasontm | |
|
Response to: Address in use
|
||
|
you need to use setsockopt() to set the SO_REUSEADDR option. that way the socket won't stay bound to a port after your program has terminated. Unix holds onto them by default just in case your program launches in the near future. there's a delay that you remove by setting SO_REUSEADDR. :)
|
||
Showing messages 1 through 1 of 1.
int yes=1;
if (setsockopt(listenfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) < 0) {
perror( "setsockopt" );
exit(1);
}
and I can start the server application right after stopping it without an error.