1
votes

I've got a Node.js app that runs fine locally, but when I push it up to OpenShift it gives me this error in the dev console:

WebSocket connection to 'ws://myapp-mydomain.rhcloud.com/socket.io/?EIO=3&transport=websocket&sid=mpKjro8KjQ5dIg0GAAAE' failed: Error during WebSocket handshake: Unexpected response code: 400

It's a little multiplayer "game", you and any other players connected are cubes that can move around and can see each other's movement etc. I use Node and socket.io to get the player positions and send the new coordinates to other players, but when I host it on OpenShift it gives me the error above. The weird thing is that it almost works i.e. you can see the other players move around, except it's very laggy and slow. The same app worked fine on Scalingo hosting, so it must be an OpenShift thing.

This is my client side code for initiating socket.io:

<script src="/socket.io/socket.io.js"></script>
<script>
    var socket = io();
</script>

And server:

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

app.get('/', function(req, res){
  res.sendFile('index.html');
});

this.ipaddress = process.env.OPENSHIFT_NODEJS_IP;
this.port      = process.env.OPENSHIFT_NODEJS_PORT || 8000;

http.listen( port, ipaddress, function(){
  console.log('listening on:'  + port);
});
1
Duplicate, maybe: stackoverflow.com/questions/19948974/… (your app still works, but poorly, because socket.io falls back to XHR long-polling which is vastly less performant than WebSockets) - apsillers
Thank you, I got it working. The performance still leaves something to be desired, there's a pretty noticeable delay (~90ms) between one player moving and the other players seeing it. - abun

1 Answers

1
votes

Thank you apsillers, changing this line did the trick:

var socket = io();//OLD
var socket = new io("ws://myapp-mydomain.rhcloud.com:8000/"); //NEW

Still a 90ms delay, but that's an issue for another time. Also a bit annoying that I have to change it back if I want to run and test the app locally (which I do).