Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unbinding a port?




On Dec 8, 2005, at 20:17 , Chilton Webb wrote:

Hi,

I am using bind and listen on a socket. Everything is going great, but I realized today that my users can't turn off the server without quitting. So at one point, I'd like to no longer listen on that socket, and free up the port it's using for other applications, while my application keeps running.

Do I use unlink to do that, or is there another way?

unlink() is used to remove a persistent name from a name space (e.g., unlink a name from a directory structure; doesn't necessarily remove the file, but the name in question will be removed).


From what you say, I think the only thing to do is close(). The accept() call that you use to get an incoming connection on a listening port will give you a new socket descriptor, while the old one is still associated with your listening socket.

If you don't want to accept any more incoming connection requests, close()ing the socket descriptor is the right thing to do.

You will have to re-bind()/listen() when you want to accept new connections, of course. You run the risk of someone having bound that port while you weren't using it, but if that's OK, you should have what you want.

Regards,

Justin

--
Justin C. Walker, Curmudgeon-At-Large
Institute for General Semantics
--------
Some people have a mental horizon of radius zero, and
call it their point of view.
  -- David Hilbert
--------


_______________________________________________ Do not post admin requests to the list. They will be ignored. Macnetworkprog mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/macnetworkprog/email@hidden

This email sent to email@hidden
References: 
 >Unbinding a port? (From: Chilton Webb <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.