Socket.io 1.4.5 Rooms issue

时间:2016-04-25 09:13:32

标签: node.js socket.io

I am unable to emit events to rooms in my server application, using version 1.4.5

I tried these two ways to communicate in a room, but neither worked.

this.io.to(this.id).emit(eventName,data);
this.io.sockets.in(this.id).emit(eventName,data);

Before calling this, i register user in the room in this fashion

user.socket.join(this.id);   

Further details

  • the this.io object is require('socket.io')(http);

  • the user.socket object is io.on('connection', function(socket)

I omitted the rest of the code because it is in overly complex structure and inheritance chain, and also irellevant to this question.

I dont necessarily require a code snippet to copy, rather a way how to debug and figure the issue out.

EDIT

When i pause the application at the moment when i want to emit the message, when I inspect the io object, i get the following.

io -> nsps -> '/' -> adapter -> rooms -> theRoomName -> sockets

And my socket id is listed there.

Is there a way how to find out whether the message is actually being sent ?

EDIT #2

When I inspect the socket object, located at

io -> sockets -> sockets -> "socket id" -> rooms 

the room id is present there as well

1 个答案:

答案 0 :(得分:0)

根据您的要求对我的评论进行回答:

要确认的前四件事是:

  1. this.io的价值是什么,它应该是什么?
  2. this.id的价值是什么,它应该是什么?
  3. 什么是eventName
  4. 客户端是否真正在侦听eventName消息?
  5. 此外,您可以使用服务器调试程序跟踪到.emit()并查看它实际上是否打算发送消息。

    然后,您可以使用服务器上的网络跟踪(如WireShark或Ethereal)来验证服务器是否实际发送了消息。

    然后,您可以使用Chrome调试器中的网络标签查看邮件是否实际到达浏览器页面。

    PostScript:听起来上面的第4项是实际问题所在。