• 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: Socket "bind" isn't working for me
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Socket "bind" isn't working for me


  • Subject: Re: Socket "bind" isn't working for me
  • From: Cameron Kerr <email@hidden>
  • Date: Sun, 24 Apr 2005 19:32:37 +1200

On 24/04/2005, at 10:34 AM, Justin Walker wrote:

Ok, but whats wrong with that? In the Windows (which is remarkebly similar to UNIX sockets), their bind can bind to more then one address...

WinSock is based on the Sockets API, with a few differences. You'll know this already by reading Beej.


If you want to re-bind a socket, you must first close that socket, then create a new socket and bind. This would mean that you may end up with a different file descriptor.

If you want to listen on multiple addresses, then you should be using multiple sockets and multiplex them using select() or poll().

Another thing I didn't mention in my earlier posting was that I was also setting my
SocketOpt to SO_REUSEADDR and SO_REUSEPORT respectively.

This doesn't allow it to rebind a port. Rather, it is allows you ignore if an address is in use. This is used for servers so they reclaim a port after crashing or restarting.


The bind() error is the fundamental issue for you. It turns out that the man page is not completely correct. The call also returns EINVAL only (AFAICT) if the socket descriptor you pass in isn't really a socket descriptor, or if there is another problem with the sockaddr structure you pass in.

Shouldn't you get an ENOTSOCK if you pass in something that isn't a socket? That's what the manual page states. In my experience teaching this stuff on Linux, it was most easily debugged using strace, which shows quite nicely what is being passed to bind(). In Mac we have ktrace and kdump, but the output is really not as useful as strace's, unless you want to process the output.


--
Cameron Kerr
email@hidden; http://humbledown.org

_______________________________________________
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


  • Follow-Ups:
    • Re: Socket "bind" isn't working for me
      • From: Justin Walker <email@hidden>
References: 
 >Re: Socket "bind" isn't working for me (From: John Draper <email@hidden>)
 >Re: Socket "bind" isn't working for me (From: Justin Walker <email@hidden>)

  • Prev by Date: Re: Socket "bind" isn't working for me.
  • Next by Date: Re: Socket "bind" isn't working for me
  • Previous by thread: Re: Socket "bind" isn't working for me
  • Next by thread: Re: Socket "bind" isn't working for me
  • Index(es):
    • Date
    • Thread