Php 触发nodeJS socket.io服务器通过端口80进行广播

Php 触发nodeJS socket.io服务器通过端口80进行广播,php,node.js,socket.io,Php,Node.js,Socket.io,实时更新机制:用户写入->php保存在mysql数据库->php发送信息到nodeJS->nodeJS发送更改所有订阅者->其他人可以实时注意到它 Socket.io服务器工作正常,在端口8080上运行。我的节点http服务器运行在端口80上。如何在http服务器上获取触发器消息并将该消息发送到所有socket.io客户端 var io = require('socket.io').listen(8080); var http = require('http'); http.createSer

实时更新机制:用户写入->php保存在mysql数据库->php发送信息到nodeJS->nodeJS发送更改所有订阅者->其他人可以实时注意到它

Socket.io服务器工作正常,在端口8080上运行。我的节点http服务器运行在端口80上。如何在http服务器上获取触发器消息并将该消息发送到所有socket.io客户端

var io = require('socket.io').listen(8080);

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Message Broadcast\n');
  console.log("Message Sent");

  //DOES NOT SEEM TO WORK, error
  io.broadcast("Messages");

  //No error but no messages
  io.emit("Message");

}).listen(80, "0.0.0.0");


/**
Other socket.io code which works well..
....

在Socket.IO 0.7中,您应使用以下命令发送到所有连接的套接字,而无需特定的套接字引用:

io.sockets.send(“消息”)

请注意,这与
广播
不同,因为这将发送到除启动连接的套接字之外的所有套接字-当然,您需要一个发送套接字引用,这就是您当前的代码不够用的原因

从wiki页面引用:

如果要向所有人发送消息,可以参考
io.sockets

io.sockets.send('message')

io.sockets.emit('event')


谢谢同样对于感兴趣的人,请查看此链接!查看wiki链接以了解其他更改。