简体   繁体   中英

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.

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.

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 版,现在可以使用了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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