php - Can a Ratchet/ReactPHP loop listen to more than one port? -
i've set reactphp websocket listener can send out near-realtime updates subscribed browsers. looks this:
use ratchet\server\ioserver; use ratchet\http\httpserver; use ratchet\websocket\wsserver; use myapp\listener; $rootpath = realpath(__dir__ . '/..'); require_once $rootpath . '/vendor/autoload.php'; $server = ioserver::factory( new httpserver( new wsserver( new listener() ) ), 8081 ); $server->run();
all of classes except listener
part of ratchet, , listener
handler implementation of \ratchet\messagecomponentinterface
, responds open/close/error events of connecting websockets.
i script contactable queue system building, , since system channel, expose on different port not reachable internet. ideally on http rather websocket; have used php websocket client contact listener, that's bit complicated compared file_get_contents('http://...')
call!
at guess, internal loop of react (e.g. streamselectloop::streamselect
) blocks short time (see here) feels possible manage number of separate streams internally. ideally, additional port handled separate listener, security isolation (in case possible flaw in guzzle allow attacker appear come restricted port when in fact came internet port).
i think not unusual requirement, there not seem related information in docs, , github issues rather bare here too. configuration possible without setting parallel processes or multithreading?
one solution problem add ip whitelisting in websocket listener specific message types. may in short term, listening on port nicer solution.
i found 1 way, may not best practice, can manually add socket, this:
use ratchet\server\ioserver; use ratchet\http\httpserver; use ratchet\websocket\wsserver; use myapp\listener; use react\socket\server reactor; $server = ioserver::factory( new httpserver( new wsserver( new listener() ) ), 8081 //port 1 ); $socket = new reactor($server->loop); $socket->listen(8082, '0.0.0.0'); //port 2 $socket->on('connection', [$server, 'handleconnect']); $server->run();
Comments
Post a Comment