在阿里云服务器上使用socket.io无法连接

原本在本地部署的项目使用socket都没有问题
放到阿里云上socket始终链接不上

前端

// 客户指派提醒消息
var socket = io('服务器外网ip:6001');
socket.on("members:assign.notification", function (data) {
    // toastr.info(data.content, data.title, {
    //     "timeOut": 14400000,
    //     "extendedTimeOut": 14400000
    // });
    console.log(data);
});

socket.io

var app = require('http').createServer(handler);
var io = require('socket.io')(app);

var Redis = require('ioredis');
var redis = new Redis(6379, '127.0.0.1');

app.listen(6001, function () {
    console.log('Socket server is running at port 6001!');
});

function handler(req, res) {
    res.writeHead(200);
    res.end('');
}

io.on('connection', function (socket) {
    socket.on('message', function (message) {
        console.log(message)
    });
    socket.on('disconnect', function () {
        console.log('user disconnect')
    });
});

客户端请求

报错 
GET https://服务器外网ip:6001/socket.io/?EIO=3&transport=polling&t=M0q8ZAs net::ERR_CONNECTION_CLOSED     
polling-xhr.js:264

网络请求用的https

我在想这是会不会是https有所影响 

第一次在阿里云上使用socket服务 遇到问题实在无法解决,恳求各位大佬给出宝贵的建议!谢谢

阅读 5.9k
2 个回答

安全组策略端口开了么~

你服务器端用的是 http,客户端请求用 https 当然有问题。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题