Re: UNbinding a socket

Discussion in 'C++' started by Sin, Jun 23, 2003.

  1. Sin

    Sin Guest

    > I've got my daemon doing everything it should, except I can't find a clean
    > way to unbind a port from a socket that's bound and listening. This

    doesn't
    > keep the program from working, but it means that if it exits I can't
    > immediately re-run it (since I have to wait for the port to unbind on it's
    > own). If I ctrl-c out of it (while it's not in the middle of
    > communications) it works fine, but otherwise if I try to find any way to
    > exit gracefully, it doesn't unbind the port.
    >
    > Anyone have a suggestion? I tried the shutdown feature, but it didn't

    seem
    > to have any effect that I could see... and nothing else looks useful (and
    > all online searches just turn up third-party libraries that I don't care

    to
    > use). There must be some simple way to do this...



    Had the same problem 2 weeks ago... Check out SO_REUSEADDR... Here's an
    example :


    // ... open socket ...

    BOOL reuse= 1;
    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(BOOL))
    < 0) {
    printf("setsockopt() failed\n");
    exit(-1);
    }

    // ... bind socket ...

    Alex.
     
    Sin, Jun 23, 2003
    #1
    1. Advertising

  2. "Sin" <> wrote in message
    news:3vIJa.1068$...
    > > I've got my daemon doing everything it should, except I can't find a

    clean
    > > way to unbind a port from a socket that's bound and listening. This

    > doesn't
    > > keep the program from working, but it means that if it exits I can't
    > > immediately re-run it (since I have to wait for the port to unbind on

    it's
    > > own). If I ctrl-c out of it (while it's not in the middle of
    > > communications) it works fine, but otherwise if I try to find any way to
    > > exit gracefully, it doesn't unbind the port.
    > >
    > > Anyone have a suggestion? I tried the shutdown feature, but it didn't

    > seem
    > > to have any effect that I could see... and nothing else looks useful

    (and
    > > all online searches just turn up third-party libraries that I don't care

    > to
    > > use). There must be some simple way to do this...

    >
    >
    > Had the same problem 2 weeks ago... Check out SO_REUSEADDR... Here's an
    > example :
    >
    >
    > // ... open socket ...
    >
    > BOOL reuse= 1;
    > if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse,

    sizeof(BOOL))
    > < 0) {
    > printf("setsockopt() failed\n");
    > exit(-1);
    > }
    >
    > // ... bind socket ...


    Thanks, worked great. Still figuring out why it works though (I
    understand what it does, just working on how it does it... hehe).
     
    Everett Hickey, Jun 24, 2003
    #2
    1. Advertising

  3. Sin

    Sin Guest

    > > Had the same problem 2 weeks ago... Check out SO_REUSEADDR... Here's an
    > > example :

    >
    > Thanks, worked great. Still figuring out why it works though (I
    > understand what it does, just working on how it does it... hehe).


    I have no idea. I just know it doesn't behave this way in Windows. Better
    ask on a proper socket programming newsgroup I guess... It has nothing to do
    with C++...

    Alex.
     
    Sin, Jun 25, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Furman

    Re: (OT) UNbinding a socket

    Michael Furman, Jun 23, 2003, in forum: C++
    Replies:
    0
    Views:
    1,411
    Michael Furman
    Jun 23, 2003
  2. Richard Spooner

    Unbinding sockets in threads..

    Richard Spooner, Aug 3, 2004, in forum: Python
    Replies:
    0
    Views:
    339
    Richard Spooner
    Aug 3, 2004
  3. Johnny Lin

    Unbinding multiple variables

    Johnny Lin, Jan 21, 2005, in forum: Python
    Replies:
    11
    Views:
    621
    Johnny Lin
    Jan 24, 2005
  4. Roger

    Tkinter unbinding

    Roger, Dec 18, 2008, in forum: Python
    Replies:
    17
    Views:
    2,953
    fabien
    Dec 4, 2011
  5. Roger
    Replies:
    7
    Views:
    705
    Roger
    Jan 13, 2009
Loading...

Share This Page