• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Unbinding a port?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unbinding a port?


  • Subject: Re: Unbinding a port?
  • From: "Justin C. Walker" <email@hidden>
  • Date: Thu, 8 Dec 2005 21:48:26 -0800


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: This email sent to email@hidden
References: 
 >Unbinding a port? (From: Chilton Webb <email@hidden>)

  • Prev by Date: Unbinding a port?
  • Next by Date: SO_BINDTODEVICE or sendto using specific network interface
  • Previous by thread: Unbinding a port?
  • Next by thread: SO_BINDTODEVICE or sendto using specific network interface
  • Index(es):
    • Date
    • Thread