Node.js, socket.io, unity - doesnt work without ngrok?


#1

Hello
Im developing a node app which involves a http server and a socket io server for interaction with unity game.
So the problem is, the only way i can connect from unity game to launched on c9 app is by using randomly granted address by ngrok http 8081
ws://workspace-user.c9users.io/socket.io/?EIO=4&transport=websocket doesnt work at all
Any tips on this?
Code looks like that:

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

    app.use(express.static('public'));

    var io = require('socket.io')(8081);

    var port = process.env.PORT || 80;

    http.listen(port, function(){

    });

#2

Can you try using ws://workspace-user.c9users.io:8081/socket.io/?EIO=4&transport=websocket (changing the port to 8081 in the URL), and see if that makes a difference? I’m not too familiar with the tools, but based on your code, it sounds like that might be the problem.


#3

Sure man I did try a lot of stuff including playing with different ports and setups.
Again like i said, the url u provided is only working with temp address by ngrok. Im just not ready to throw 5usd for ngrok premium yet to have static address.:grinning:


#4

What error do you get with ws://workspace-user.c9users.io/socket.io/?EIO=4&transport=websocket? Does this happen because of clickthrough page?


#5

I dont think there are any clickthrough pages.
And i dont see any errors, this lib https://github.com/fpanettieri/unity-socket.io-DEPRECATED/tree/master/SocketIO just prints “connecting” and then nothing.
Yeah its deprecated but it works on any other hosting and locally as well.