Women in Technology

Hear us Roar



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. :)


use the mighty Google to find out more.. i'm too tired to launch into a tutorial. :P


good luck..

Full Threads Oldest First

Showing messages 1 through 1 of 1.

  • Address in use
    2002-12-29 17:44:43  johnts [View]

    Got it to work, using code from Beej's Guide page mentioned in another post - there was the exact description of the problem too. I added:

    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.