Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot bind IPv6 [::] (any) #58

Closed
maxxer opened this issue Jan 13, 2017 · 6 comments
Closed

Cannot bind IPv6 [::] (any) #58

maxxer opened this issue Jan 13, 2017 · 6 comments
Labels

Comments

@maxxer
Copy link

maxxer commented Jan 13, 2017

        $loop = \React\EventLoop\Factory::create();
        $ip4 = new \React\Socket\Server($loop);
        $ip6 = new \React\Socket\Server($loop);
        $ip4->listen(9988, '0.0.0.0');
        $ip6->listen(9988, '::');

        $wsStack = new \Ratchet\Http\HttpServer(
            new WsServer(
                new Online()
            )
        );

        $ip4App = new IoServer($wsStack, $ip4, $loop);
        $ip6App = new IoServer($wsStack, $ip6, $loop);
        $loop->run();

This fails with:
Exception 'React\Socket\ConnectionException' with message 'Could not bind to tcp://[::]:9988: Address already in use'

But address is not in use, in fact if I replace :: with the actual machine public IPv6 address works fine.

@clue clue added the question label Jan 13, 2017
@clue
Copy link
Member

clue commented Jan 13, 2017

Thanks for reporting!

The example code essentially executes this under the hood:

$a = stream_socket_server('tcp://0.0.0.0:9988');
$b = stream_socket_server('tcp://[::]:9988');

Which emits the very same error.

If you omit the first server, then the second works just fine. It looks like this is intended behavior.

I hope this helps 👍

@clue clue closed this as completed Jan 13, 2017
@maxxer
Copy link
Author

maxxer commented Jan 13, 2017

If that's intended how to open a socket for both v6/v4?

@maxxer
Copy link
Author

maxxer commented Jan 13, 2017

Maybe this is related?
https://bugs.php.net/bug.php?id=73307

@maxxer
Copy link
Author

maxxer commented Jan 13, 2017

I'm on linux and indeed this happens to be true. Using just the IPv6 [::] address listens on both the stacks, because my ubuntu server has 0 in /proc/sys/net/ipv6/bindv6only

@clue
Copy link
Member

clue commented Jan 13, 2017

Thanks for confirming this! 👍

I've just filed feature request #59 so you may eventually specify the ipv6_v6only context option 👍

@clue
Copy link
Member

clue commented Jan 26, 2017

For the reference, #64 introduced the required socket context options, so you may want to check out the v0.4.6 release 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants