Jump to content

Socket_Bind() To More Than One Ip:port ?


AliceWonder32

Recommended Posts

If you bind to 0.0.0.0 then it will bind to all available IPv4 addresses. There is probably something similar for IPv6 but I do not know it off the top of my head.

 

To sort of address the question in a general sense though, I'm pretty sure you'd need one socket for each protocol. If you wanted to bind specific addresses rather than "all addresses" I'm pretty sure you'd need a socket for each address/port combo.

 

To sort of address the question in a general sense though, I'm pretty sure you'd need one socket for each protocol. If you wanted to bind specific addresses rather than "all addresses" I'm pretty sure you'd need a socket for each address/port combo.

That's spot-on. I was thinking of 0.0.0.0 but that's only IPv4. The underlying constants for binding (on Linux) AF_INET and AF_INET6 so that requires two calls to bind(). So actually no, it's definitely not possible to listen to both IPv4 and IPv6 - unless there's something which hides that kind of detail from you.

Thanks. I wonder if a pecl wrapper could be written to solve this issue, e.g. the wrapper provides something that looks and behaves like a socket but proxies multiple sockets, so you create and bind multiple sockets, and then the wrapper socket listens on them much like binding to 0.0.0.0:port would do.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.