I agree with the Mayberlin idea of the order of these events.
Run:
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
io.on('connection', function(socket){
console.log('connection',socket.id);
io.on('connect',function (socket) {
console.log('conenct',socket.id);
});
});
http.listen(1111);
And you will get something like:
connection 6Song1KpSUoUkKgPAAAA
But if you try
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
io.on('connect',function (socket) {
console.log('conenct',socket.id);
io.on('connection', function(socket){
console.log('connection',socket.id);
});
});
http.listen(1111);
You should get something like:
conenct pSlSKNaabR2LBCujAAAA
connection pSlSKNaabR2LBCujAAAA
This proves that socket.io will process connectfirst and then connection.
source
share