node.js socket.io 无法发送到特定客户端 [英] node.js socket.io cannot send to specific client

查看:34
本文介绍了node.js socket.io 无法发送到特定客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一些对此的引用,但没有任何直接的帮助.此外,根据一些研究,这是向特定客户端发送消息的正确方式.我有:

I found a few references to this but nothing that actually direct helps. Also according to some research this is the proper way to send a message to a specific client. I have:

io.sockets.socket(players[i].id).emit('deal_card', {
    // etc
});

我在该行收到此错误:

Missing error handler on 'socket'.TypeError: Object #<Namespace> has no method 'socket'

有什么想法吗?

推荐答案

对于 socket.io 1.0 使用:

For socket.io 1.0 use:

io.sockets.connected[players[i].id].emit('deal_card', {..});

对于 0.9 使用:

io.sockets.sockets[players[i].id].emit('deal_card', {..});

(不是 io.sockets.socket[players[i].id].emit('deal_card', {..});)

(not io.sockets.socket[players[i].id].emit('deal_card', {..});)

这篇关于node.js socket.io 无法发送到特定客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆