0

I am trying to start ReactPHP TCP sockets on a range of TCP ports (1000 to 2000). All the ports are open and I can see the connection established while testing using telnet but the sockets never fires the connection.on('data' ...) event. Using any kind of port forwarding is not an option. Everything works while using a smaller port range of exactly 255 socket instead of 1000.

<?php
require 'vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
for ($i = 1000; $i < 2000; $i++) {
    $socket[$i] = new React\Socket\Server('127.0.0.1:' . $i, $loop);
    $socket[$i]->on('connection', function (React\Socket\ConnectionInterface $connection) {
        echo "connection happened";
        $connection->write("Hello " . $connection->getRemoteAddress() . "!\n"); // this part works 
        $connection->on('data', function ($data) use ($connection) {
            echo $data; // for some reason this never fires
        });
    });
}
$loop->run();
user2576266
  • 2,383
  • 2
  • 16
  • 22
  • Out of curiosity - why would you create 1000 sockets and bind to 1000 ports? What's the use case here? Is it just testing and playing around or you're trying to create something that will be used in production? – Mjh Apr 05 '19 at 07:53
  • build a network black hole, but it is not exactly a black hole since I am willing to answer these connections. – user2576266 Apr 05 '19 at 08:17

0 Answers0