ratchetphp / Ratchet

Asynchronous WebSocket server
http://socketo.me
MIT License
6.27k stars 738 forks source link

An attempt was made to access a socket in a way forbidden by its access permissions. #409

Closed samphors closed 8 years ago

samphors commented 8 years ago

I have followed all the steps in the blog, after I started to run the common line that pointed to the server.php. finally I got this such error messages.

Fatal error: Uncaught exception 'React\Socket\ConnectionException' with message 'Could not bind to tcp://0.0.0.0:2000: An attempt was made to access a socket in a way forbidden by its access permissions.
' in C:\xampp\htdocs\ratchet\vendor\react\socket\src\Server.php:29
Stack trace:
#0 C:\xampp\htdocs\ratchet\vendor\cboden\ratchet\src\Ratchet\Server\IoServer.php(70): React\Socket\Server->listen(2000, '0.0.0.0')
#1 C:\xampp\htdocs\ratchet\bin\chat-server.php(10): Ratchet\Server\IoServer::factory(Object(MyApp\Chat), 2000)
#2 {main}
  thrown in C:\xampp\htdocs\ratchet\vendor\react\socket\src\Server.php on line 29

I don't exactly know why it shown this. I tired to search and asked the forum and some said that it cause could be of my private network connection on window 8, or other application were also running.

Could anyone told me how to deal with this?

cboden commented 8 years ago

This sounds like a permission error at the operating system level. I'm not at all familiar with Windows but suspect there's a firewall that is preventing users from binding to and serving a port. Take a look at security or firewall settings or perhaps trying to run the command as an administrator.

jankube commented 8 years ago

on running the server.php via ssh it says <b>Parse error</b>: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in <b>/etc/etc/application/third_party/Realtime/bin/server.php</b> on line <b>5</b><

Any hint how I could solve that, please?

fauzzi commented 7 years ago

Same issue for windows 10, I already stop firewall and run as administrator for the command prompt

Fatal error: Uncaught exception 'RuntimeException' with message 'Failed to listen on "tcp://127.0.0.1:5555": An attempt was made to access a socket in a way forbidden by its access permissions. ' in C:\xampp\htdocs\socketo\vendor\react\socket\src\TcpServer.php:164 Stack trace: #0 C:\xampp\htdocs\socketo\vendor\react\socket\src\Server.php(31): React\Socket\TcpServer->__construct('tcp://127.0.0.1...', Object(React\EventLoop\StreamSelectLoop), Array) #1 C:\xampp\htdocs\socketo\bin\push-server.php(22): React\Socket\Server->__construct('tcp://127.0.0.1...', Object(React\EventLoop\StreamSelectLoop)) #2 {main} thrown in C:\xampp\htdocs\socketo\vendor\react\socket\src\TcpServer.php on line 164

`<?php

use Ratchet\Server\IoServer; use Ratchet\Http\HttpServer; use Ratchet\WebSocket\WsServer; use MyApp\Pusher;

require dirname(DIR) . '/vendor/autoload.php';

$loop   = React\EventLoop\Factory::create();
$pusher = new Pusher;

// Listen for the web server to make a ZeroMQ push after an ajax request
$context = new React\ZMQ\Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('tcp://127.0.0.1:5555'); // Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on('message', array($pusher, 'onBlogEntry'));

// Set up our WebSocket server for clients wanting real-time updates    
$webSock = new React\Socket\Server('tcp://127.0.0.1:5555',$loop);
$webSock->listen(8090, '0.0.0.0'); // Binding to 0.0.0.0 means remotes can connect
$webServer = new Ratchet\Server\IoServer(
    new Ratchet\Http\HttpServer(
        new Ratchet\WebSocket\WsServer(
            new Ratchet\Wamp\WampServer(
                $pusher
            )
        )
    ),
    $webSock
);

$loop->run();`

object(RuntimeException)#18 (7) { ["message":protected]=> string(130) "Failed to listen on "tcp://127.0.0.1:5555": An attempt was made to access a socket in a way forbidden by its access permissions. " ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(61) "C:\xampp\htdocs\socketo\vendor\react\socket\src\TcpServer.php" ["line":protected]=> int(164) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(58) "C:\xampp\htdocs\socketo\vendor\react\socket\src\Server.php" ["line"]=> int(31) ["function"]=> string(11) "__construct" ["class"]=> string(22) "React\Socket\TcpServer" ["type"]=> string(2) "->" ["args"]=> array(3) { [0]=> string(20) "tcp://127.0.0.1:5555" [1]=> object(React\EventLoop\StreamSelectLoop)#3 (8) { ["nextTickQueue":"React\EventLoop\StreamSelectLoop":private]=> object(React\EventLoop\Tick\NextTickQueue)#2 (2) { ["eventLoop":"React\EventLoop\Tick\NextTickQueue":private]=> *RECURSION* ["queue":"React\EventLoop\Tick\NextTickQueue":private]=> object(SplQueue)#4 (2) { ["flags":"SplDoublyLinkedList":private]=> int(4) ["dllist":"SplDoublyLinkedList":private]=> array(0) { } } } ["futureTickQueue":"React\EventLoop\StreamSelectLoop":private]=> object(React\EventLoop\Tick\FutureTickQueue)#5 (2) { ["eventLoop":"React\EventLoop\Tick\FutureTickQueue":private]=> *RECURSION* ["queue":"React\EventLoop\Tick\FutureTickQueue":private]=> object(SplQueue)#6 (2) { ["flags":"SplDoublyLinkedList":private]=> int(4) ["dllist":"SplDoublyLinkedList":private]=> array(0) { } } } ["timers":"React\EventLoop\StreamSelectLoop":private]=> object(React\EventLoop\Timer\Timers)#7 (3) { ["time":"React\EventLoop\Timer\Timers":private]=> NULL ["timers":"React\EventLoop\Timer\Timers":private]=> object(SplObjectStorage)#8 (1) { ["storage":"SplObjectStorage":private]=> array(0) { } } ["scheduler":"React\EventLoop\Timer\Timers":private]=> object(SplPriorityQueue)#9 (3) { ["flags":"SplPriorityQueue":private]=> int(1) ["isCorrupted":"SplPriorityQueue":private]=> bool(false) ["heap":"SplPriorityQueue":private]=> array(0) { } } } ["readStreams":"React\EventLoop\StreamSelectLoop":private]=> array(1) { [26]=> resource(26) of type (stream) } ["readListeners":"React\EventLoop\StreamSelectLoop":private]=> array(1) { [26]=> array(2) { [0]=> object(React\ZMQ\SocketWrapper)#14 (6) { ["fd"]=> resource(26) of type (stream) ["closed"]=> bool(false) ["socket":"React\ZMQ\SocketWrapper":private]=> object(ZMQSocket)#13 (0) { } ["loop":"React\ZMQ\SocketWrapper":private]=> *RECURSION* ["buffer":"React\ZMQ\SocketWrapper":private]=> object(React\ZMQ\Buffer)#15 (8) { ["socket"]=> object(ZMQSocket)#13 (0) { } ["closed"]=> bool(false) ["listening"]=> bool(false) ["loop":"React\ZMQ\Buffer":private]=> *RECURSION* ["fd":"React\ZMQ\Buffer":private]=> resource(26) of type (stream) ["writeListener":"React\ZMQ\Buffer":private]=> array(2) { [0]=> *RECURSION* [1]=> string(11) "handleEvent" } ["messages":"React\ZMQ\Buffer":private]=> array(0) { } ["listeners":protected]=> array(0) { } } ["listeners":protected]=> array(1) { ["message"]=> array(1) { [0]=> array(2) { [0]=> object(MyApp\Pusher)#10 (1) { ["subscribedTopics":protected]=> array(0) { } } [1]=> string(11) "onBlogEntry" } } } } [1]=> string(11) "handleEvent" } } ["writeStreams":"React\EventLoop\StreamSelectLoop":private]=> array(0) { } ["writeListeners":"React\EventLoop\StreamSelectLoop":private]=> array(0) { } ["running":"React\EventLoop\StreamSelectLoop":private]=> NULL } [2]=> array(0) { } } } [1]=> array(6) { ["file"]=> string(43) "C:\xampp\htdocs\socketo\bin\push-server.php" ["line"]=> int(24) ["function"]=> string(11) "__construct" ["class"]=> string(19) "React\Socket\Server" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> string(20) "tcp://127.0.0.1:5555" [1]=> object(React\EventLoop\StreamSelectLoop)#3 (8) { ["nextTickQueue":"React\EventLoop\StreamSelectLoop":private]=> object(React\EventLoop\Tick\NextTickQueue)#2 (2) { ["eventLoop":"React\EventLoop\Tick\NextTickQueue":private]=> *RECURSION* ["queue":"React\EventLoop\Tick\NextTickQueue":private]=> object(SplQueue)#4 (2) { ["flags":"SplDoublyLinkedList":private]=> int(4) ["dllist":"SplDoublyLinkedList":private]=> array(0) { } } } ["futureTickQueue":"React\EventLoop\StreamSelectLoop":private]=> object(React\EventLoop\Tick\FutureTickQueue)#5 (2) { ["eventLoop":"React\EventLoop\Tick\FutureTickQueue":private]=> *RECURSION* ["queue":"React\EventLoop\Tick\FutureTickQueue":private]=> object(SplQueue)#6 (2) { ["flags":"SplDoublyLinkedList":private]=> int(4) ["dllist":"SplDoublyLinkedList":private]=> array(0) { } } } ["timers":"React\EventLoop\StreamSelectLoop":private]=> object(React\EventLoop\Timer\Timers)#7 (3) { ["time":"React\EventLoop\Timer\Timers":private]=> NULL ["timers":"React\EventLoop\Timer\Timers":private]=> object(SplObjectStorage)#8 (1) { ["storage":"SplObjectStorage":private]=> array(0) { } } ["scheduler":"React\EventLoop\Timer\Timers":private]=> object(SplPriorityQueue)#9 (3) { ["flags":"SplPriorityQueue":private]=> int(1) ["isCorrupted":"SplPriorityQueue":private]=> bool(false) ["heap":"SplPriorityQueue":private]=> array(0) { } } } ["readStreams":"React\EventLoop\StreamSelectLoop":private]=> array(1) { [26]=> resource(26) of type (stream) } ["readListeners":"React\EventLoop\StreamSelectLoop":private]=> array(1) { [26]=> array(2) { [0]=> object(React\ZMQ\SocketWrapper)#14 (6) { ["fd"]=> resource(26) of type (stream) ["closed"]=> bool(false) ["socket":"React\ZMQ\SocketWrapper":private]=> object(ZMQSocket)#13 (0) { } ["loop":"React\ZMQ\SocketWrapper":private]=> *RECURSION* ["buffer":"React\ZMQ\SocketWrapper":private]=> object(React\ZMQ\Buffer)#15 (8) { ["socket"]=> object(ZMQSocket)#13 (0) { } ["closed"]=> bool(false) ["listening"]=> bool(false) ["loop":"React\ZMQ\Buffer":private]=> *RECURSION* ["fd":"React\ZMQ\Buffer":private]=> resource(26) of type (stream) ["writeListener":"React\ZMQ\Buffer":private]=> array(2) { [0]=> *RECURSION* [1]=> string(11) "handleEvent" } ["messages":"React\ZMQ\Buffer":private]=> array(0) { } ["listeners":protected]=> array(0) { } } ["listeners":protected]=> array(1) { ["message"]=> array(1) { [0]=> array(2) { [0]=> object(MyApp\Pusher)#10 (1) { ["subscribedTopics":protected]=> array(0) { } } [1]=> string(11) "onBlogEntry" } } } } [1]=> string(11) "handleEvent" } } ["writeStreams":"React\EventLoop\StreamSelectLoop":private]=> array(0) { } ["writeListeners":"React\EventLoop\StreamSelectLoop":private]=> array(0) { } ["running":"React\EventLoop\StreamSelectLoop":private]=> NULL } } } } ["previous":"Exception":private]=> NULL }

luisgarso commented 6 years ago

Hello ! I have tested your script and it works perfect, but when I tried to test it on a LAMP everything seems to be ok, but and I got this message

WebSocket connection to 'wss://x.x.x.x:2000/' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT

Do you have any idea how to fix it or where could be the problem?

I would appreciate any possible help. Thanks

Mecanik commented 6 years ago

3 separate issues in the same issue, well I guess that's how we do it nowadays.

The correct way to start and run Ratchet on Windows:

$chatServer = /** YOUR SERVER CONTROLLER */
$port = 1234;
$ip='0.0.0.0';

$wsServer = new WsServer($chatServer);
$wsServer->disableVersion(0); // old, bad, protocol version

$http = new HttpServer($wsServer);
$server = IoServer::factory($http, $port, $ip);

$server->run();

This will work on LAMP,WAMP,XAMPP and whatever package you will use.

PS: Don't use Windows CMD... install and use Cygwin instead.