加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

Socket.io无法连接nginx node.js php app

发布时间:2020-12-13 21:37:53 所属栏目:Nginx 来源:网络整理
导读:我试图用PHP app和node.js一起运行nginx(这部分工作正常).另外我想将socket.io添加到此设置中,但不幸的是我无法在客户端和服务器之间建立连接(看起来像连接超时?). server.js var app = require("http"),redis = require("redis"),io = require('socket.io'

我试图用PHP app和node.js一起运行nginx(这部分工作正常).另外我想将socket.io添加到此设置中,但不幸的是我无法在客户端和服务器之间建立连接(看起来像连接超时?).

server.js

var app = require("http"),redis = require("redis"),io = require('socket.io')(app);


io.sockets.on( 'connection',function( client ) {
    console.log( "New client !" );

    io.sockets.emit('msg',{ msg: 'Foo bar' } );
});

app.createServer().listen(3000);
console.log("Server running at 127.0.0.1:3000");

client.js