M
M
ML2016-05-24 14:54:16
JavaScript
ML, 2016-05-24 14:54:16

Room socket.io?

Just started to study work with sockets, it's not clear yet.
The following picture is drawn in my head:
Server:

var io = require( 'socket.io' )( http );
io.sockets.on( 'connection', function( socket ) {
    socket.to( 'room_1' ).emit( 'msg', 'text' );
} );

Customer:
var socket = io( 'http://examle.loc/' );
socket.on( 'msg', function( msg ) {
       console.log( msg );
} );

And in theory, a message should already be displayed in the console (as I read from the documentation).
But alas...
Can I get a short, but at the same time, a valuable guide on how to work with rooms in socket.io?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2016-05-24
@staffID

It will be displayed as soon as you send it to the client, or to all clients.
You send a message to room_1, but no one enters it.
To get it, the client needs to join in the right room.
Or do emit/broadcast,

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question