简体   繁体   English

使用自定义命名空间连接到 Heroku 套接字 io 服务器的套接字 io 超时

[英]Socket io timeout connecting to heroku socket io server with custom namespace

I'm trying to connect to my server located in heroku with socket io with this code, which works when the server is ran locally but, when I try to connect to the same server on herkoku it won't connect and it will give me a timeout.我正在尝试使用此代码使用 socket io 连接到位于 heroku 中的服务器,该代码在服务器在本地运行时有效,但是,当我尝试连接到 herkoku 上的同一台服务器时,它无法连接,它会给我超时。

I've tried setting transport to websocket on the client and it gives me websocket error on chrome and can't establish connection on firefox.我已经尝试在客户端上将传输设置为 websocket,它在 chrome 上给我 websocket 错误并且无法在 firefox 上建立连接。

Client side code:客户端代码:

const io = require('socket.io-client');    
socket = io.connect('https://herokuappurl.com:23840/custom_nsp');//not works
socket = io.connect('localhost:23840/custom_nsp');//works

Server side code:服务器端代码:

var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);

const PORT = process.env.PORT || 8000;
var server = http.listen(PORT,function(){
   print('listening on *:' + PORT);
});
io.of('/custom_nsp').on('connection', function(socket) {
   /*socket.on events*/
}

我降级到 1.7 版,现在可以使用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM