我试图将 socket.io 引入到我用 Laravel 和 AngularJS 开发的应用程序中。
该应用程序在我的计算机上运行良好,但是当我尝试使其在服务器上运行时,我收到错误“ GET http://localhost:8080/socket.io/?EIO=3&transport=polling&t=LQxpNjO net::ERR_CONNECTION_REFUSED ” 。
服务器运行的是 Ubuntu 16.04,我使用 nginx 作为 Web 服务器。
这是创建 Nodejs 服务器的文件:
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var Redis = require('ioredis');
var redis = new Redis();
var port = 8080;
http.listen(port, function() {
console.log('Listening on *:' + port);
});
io.on('connection', function (socket) {
console.info('Client connected');
redis.subscribe('counter.increase');
redis.on('message', function (channel, message) {
console.log('Received message ' + message + ' in channel ' + …Run Code Online (Sandbox Code Playgroud)