php - Pass socket.io room with socket_write? -


i curently using socket_write open websocket , pass data node.js socket.io server. sending bits of html so:

private function opensocketconnection($address = 'localhost', $port = 5600) {     $socket = socket_create(af_inet, sock_stream, sol_tcp);     socket_connect($socket, $address, $port);      return $socket; }  $socket = $this->opensocketconnection();  socket_write($socket, $html, strlen($html)); 

this works fine , sends data node.js socket.io server catch so:

socket.on('data', (msg) => {});

but want send data specific room instead of general socket.io room. there way setup can specify room?

perhaps when using socket_create() or something? prevent pass room name on every socket_write if possible.

clients can send data server itself. if want send message users in specific room, create message client can send tell server on behalf of client.

// client-side socket.emit("sendtoroom", {room: "someroom", data: "hello"}); 

and, on server:

socket.on('sendtoroom', function(msg) {     // send clients in room except socket client     socket.broadcast.to(msg.room, msg.data); }); 

if client in 1 room, can have client send message broadcast current room , have server room it's in. way, client not have send room every time.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -