웹 응용 프로그램에 socket.io 및 Mean 스택을 사용하고 있습니다. 내가 3006 포트 소켓에 대한 서버를 시작했다.io.on ('connection', ...) vs io.sockets.on ('connection', ...)
var http = require('http').createServer(app);
http.listen(3006);
var io = require('socket.io').listen(http);
이 두 가지 모두 연결에 작동하는 것 같습니다.
io.on('connection', function (socket) {
console.log('Socket succesfully connected with id: '+socket.id);
});
및
io.sockets.on('connection', function (socket) {
console.log('Socket succesfully connected with id: '+socket.id);
});
...
I가 처음 접속에 사용되어야 하나 io.on
및 io.sockets.on
과의 차이점은 무엇
/
: 그것은
io.sockets.on
100 % 아니지만 별칭 일뿐입니다. 'io.sockets.emit'과'io.emit'와 같이 [here] (http://socket.io/docs/server-api/#server#emit). –
@Ben Fortune 같은 시간에 양쪽 모두 가지고있을 때 둘 다 실행됩니다 .. io.on ('connection', ...)을 두 번 사용하는 것은 잘못입니까? – Srinath