Socket.io客户端未收到事件

时间:2018-08-26 18:40:13

标签: javascript node.js socket.io socket.io-1.0

当两个客户加入聊天室时,我想向他们发送一条唯一的消息。第一个客户端收到消息,但第二个客户端没有收到消息。这是代码:

python -c "import os, sys; print(os.linesep.join(sys.path))"

我该如何调试?如果socket.io无法发送消息,有什么办法可以看到错误?

1 个答案:

答案 0 :(得分:1)

API doc中有一个警告,指出为什么它不起作用:

url %>%
  read_html() %>%
  html_nodes("li.grpl-moreinfo a") %>%
  html_attr("href")

#[1] "?mode=form&id=5bf9ea61bc46eaeff075cf8043c27c92&tab=profile"
#[2] "?mode=form&id=17e4ea613be85fe019efcf728fb6361d&tab=profile"
#[3] "?mode=form&id=d593eb48fe26d58f616515366a1e677b&tab=profile"
...

您可以按照API doc所述使用// sending to individual socketid (private message) io.to(`${socketId}`).emit('hey', 'I just met you'); // WARNING: `socket.to(socket.id).emit()` will NOT work, as it will send to everyone in the room // named `socket.id` but the sender. Please use the classic `socket.emit()` instead.

socket.broadcast
相关问题