src/Server.php
public function onConnection(ConnectionInterface $connection)
    {
        $this->log('New connection from ' . $connection->getRemoteAddress());

        $buffer = '';
        $connection->on('data', function ($data) use (&$buffer, &$connection) {
            $buffer .= $data;

            if (strpos($buffer, Client::END_OF_COMMAND)) {
                $chunks = explode(Client::END_OF_COMMAND, $buffer);
                $count = count($chunks);
                $buffer = $chunks[$count - 1];

                for ($i = 0; $i < $count - 1; $i++) {
                    $command = json_decode($chunks[$i], true);
                    $this->runCommand($command, $connection);
                }
            }
        });
    }
public function onConnection(ConnectionInterface $connection)
    {
        $this->log('New connection from ' . $connection->getRemoteAddress());

        $buffer = '';
        $connection->on('data', function ($data) use (&$buffer, &$connection) {
            $buffer .= $data;

            if (strpos($buffer, Client::END_OF_COMMAND)) {
                $chunks = explode(Client::END_OF_COMMAND, $buffer);
                $count = count($chunks);
                $buffer = $chunks[$count - 1];

                for ($i = 0; $i < $count - 1; $i++) {
                    $command = json_decode($chunks[$i], true);
                    $this->runCommand($command, $connection);
                }
            }
        });
    }
public function onConnection ( ConnectionInterface $ connection ) { $ this -> log ( 'New connection from ' . $ connection -> getRemoteAddress ( ) ) ; $ buffer = '' ; $ connection -> on ( 'data' , function ( $ data ) use ( & $ buffer , & $ connection ) { $ buffer .= $ data ; if ( strpos ( $ buffer , Client :: END_OF_COMMAND ) ) { $ chunks = explode ( Client :: END_OF_COMMAND , $ buffer ) ; $ count = count ( $ chunks ) ; $ buffer = $ chunks [ $ count - 1 ] ; for ( $ i = 0 ; $ i < $ count - 1 ; $ i ++ ) { $ command = json_decode ( $ chunks [ $ i ] , true ) ; $ this -> runCommand ( $ command , $ connection ) ; } } } ) ; }
On every new connection add event handler to receive commands from clients.

@param ConnectionInterface $connection
On every new connection add event handler to receive commands from clients .