Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Re: UNbinding a socket (http://www.velocityreviews.com/forums/t267621-re-unbinding-a-socket.html)

Sin 06-23-2003 07:23 PM

Re: UNbinding a socket
 
> 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.



Everett Hickey 06-24-2003 01:26 PM

Re: UNbinding a socket
 
"Sin" <broa29@hotmail.com> wrote in message
news:3vIJa.1068$OE2.235805@news20.bellglobal.com.. .
> > 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).



Sin 06-25-2003 06:27 PM

Re: UNbinding a socket
 
> > 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.




All times are GMT. The time now is 08:52 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.