Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Socket.io客户端上的多个连接_Node.js_Sockets - Fatal编程技术网

Node.js Socket.io客户端上的多个连接

Node.js Socket.io客户端上的多个连接,node.js,sockets,Node.js,Sockets,我试图在同一页(客户端)上有多个套接字io连接。我尝试过这个答案,但不幸的是它没有解决问题 案例: 我在localhost:3000上运行了一个聊天(bot)应用程序 我有一个CMS,用于运行在localhost:8000上的上述聊天(bot)应用程序 我的代码当前为: 1.在index.html上声明脚本(在localhost:3000上) 让我困惑的是,来自两个套接字的控制台日志工作了,告诉两个套接字连接,尽管('test\u cms\u socket',…)上的cms\u socket

我试图在同一页(客户端)上有多个套接字io连接。我尝试过这个答案,但不幸的是它没有解决问题

案例:

  • 我在localhost:3000上运行了一个聊天(bot)应用程序
  • 我有一个CMS,用于运行在localhost:8000上的上述聊天(bot)应用程序
我的代码当前为:

1.在index.html上声明脚本(在localhost:3000上)

让我困惑的是,来自两个套接字的控制台日志工作了,告诉两个套接字连接,尽管('test\u cms\u socket',…)上的
cms\u socket.on不工作

以下是CMS本地主机的逻辑:8000

function broadcast(req,res){
   res.io.emit('test_cms_socket', "This is from CMS");
   return res.redirect('/');
}
我已经将我的socket.io传递给中间件,使用了来自的教程

我真的不知道这是否有帮助,但我从控制台得到这个错误。任何帮助都将不胜感激

Uncaught TypeError: Cannot read property 'apply' of undefined
    at r.emit (index.js:133)
    at r.emit (socket.js:136)
    at r.onconnect (socket.js:327)
    at r.onpacket (socket.js:224)
    at r.<anonymous> (index.js:21)
    at r.emit (index.js:133)
    at r.ondecoded (manager.js:345)
    at s.<anonymous> (index.js:21)
    at s.r.emit (index.js:133)
    at s.add (index.js:241)
未捕获类型错误:无法读取未定义的属性“apply”
在r.emit(index.js:133)
在r.emit(socket.js:136)
在r.onconnect(socket.js:327)
at r.onpacket(socket.js:224)
在r。(索引:21)
在r.emit(index.js:133)
在r.O.S(manager.js:345)
在s。(索引:21)
在s.r.emit(索引:133)
在s.add(index.js:241)

可能重复@daviscodebugs是的,我尝试过这个解决方案,但它对我不起作用*我也在我的第一段中链接了它@daviscodebugs的可能副本是的,我尝试过这个解决方案,但它对我不起作用*我在第一段中也把它联系了起来
function broadcast(req,res){
   res.io.emit('test_cms_socket', "This is from CMS");
   return res.redirect('/');
}
Uncaught TypeError: Cannot read property 'apply' of undefined
    at r.emit (index.js:133)
    at r.emit (socket.js:136)
    at r.onconnect (socket.js:327)
    at r.onpacket (socket.js:224)
    at r.<anonymous> (index.js:21)
    at r.emit (index.js:133)
    at r.ondecoded (manager.js:345)
    at s.<anonymous> (index.js:21)
    at s.r.emit (index.js:133)
    at s.add (index.js:241)