AliceWonder32 Posted October 22, 2012 Share Posted October 22, 2012 Working on php socket server. New to sockets. Would love to support IPv6 in addition to IPv4. Sure, I could proxy IPv6 requests to IPv4 but I'd rather not. Can I bind the same socket to more than one IP:port ?? Quote Link to comment https://forums.phpfreaks.com/topic/269759-socket_bind-to-more-than-one-ipport/ Share on other sites More sharing options...
requinix Posted October 22, 2012 Share Posted October 22, 2012 Nope. You could bind to a port only though. Quote Link to comment https://forums.phpfreaks.com/topic/269759-socket_bind-to-more-than-one-ipport/#findComment-1386881 Share on other sites More sharing options...
kicken Posted October 22, 2012 Share Posted October 22, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/269759-socket_bind-to-more-than-one-ipport/#findComment-1386884 Share on other sites More sharing options...
requinix Posted October 22, 2012 Share Posted October 22, 2012 (edited) 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. Edited October 22, 2012 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/269759-socket_bind-to-more-than-one-ipport/#findComment-1386891 Share on other sites More sharing options...
AliceWonder32 Posted October 22, 2012 Author Share Posted October 22, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/269759-socket_bind-to-more-than-one-ipport/#findComment-1386894 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.