Answer the question
In order to leave comments, you need to log in
SocketIO and a large number of events?
The question arose, in the vast majority of socket examples, the following construction is used:
io = require('socket.io').listen(httpsServer);
io.on('connection', function(socket) {
socket.on('listener1', function(e) {
//code
}),
socket.on('listener2', function(e) {
//code
}),
...etc
});
Answer the question
In order to leave comments, you need to log in
Yes, there is no "situation". When 100 clients connect, 100 socket objects will be created - each with a unique ID. And "listeners" of events are not asked, they only listen to them and, upon receipt, give them to handlers - this is an abstraction common to all connections.
In my opinion the example somehow looks strange.
"socket.on" occurs on some event, not on the arrival of a new user.
That is, for example, a client (one or a thousand) says
A on the server side
io = require('socket.io').listen(httpsServer);
io.on('connection', function(socket) {
socket.on('getUserInfo', function(e) {
//code
...
socket.emit('sendUserInfo', data)
})
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question