我在我的server.js文件中有这个
var app = require('express');
var http = require('http');
var server = app();
server.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
}
);
server.listen(81);
var io = require('socket.io').listen(82);;
io.on('connection', function (socket) {
io.emit('this', { will: 'be received by everyone'});
socket.on('private message', function (from, msg) {
console.log('I received a private message by ', from, ' saying ', msg);
io.emit('done','done from server');
});
socket.on('disconnect', function () {
io.sockets.emit('user disconnected');
});
});
它在本地工作正常但是当我将它部署到我的网站并尝试从服务器上连接它时总是超时给我这个错误
我有一个像这样的javascript客户端
var socket = io.connect('ws://xxxxxxxxx.xxxxxxxx.net:82/');
它总是给我那个错误
GET http://xxxxxxxxx.xxxxxxxx.net:82/socket.io/?EIO=2&transport=polling&t=1403458443180-0 net::ERR_CONNECTION_TIMED_OUT socket.io-1.0.0-pre5.js:2
有人可以帮助我,让我知道它为什么总是超时?