1
votes

On OpenShift which is supposed to support websockets, using the following socket.io code I get this response:

Error during WebSocket handshake: Unexpected response code: 502

In logs, I can see this:

warn: websocket connection invalid

Sockets then fallback to xhr-polling. I think I once had it working, but don't know what did I change that could break it.

Or, could it be that openshift would stop supporting websockets after latest upgrades?

The code (node.js server, socket.io)

var server = require('http').createServer(self.app);

server.listen(self.port, self.ipaddress, function() {
     console.log('%s: Node server started on %s:%d ...', Date(Date.now() ), self.ipaddress, self.port);
});

var io = require('socket.io').listen(server);

io.configure(function () { 
    io.set("polling duration", 120); 
    io.set("heartbeat timeout", 120);
    io.set("close timeout", 120);
});            

io.sockets.on('connection', function (socket) {
    socket.on('message', function (data) {
        socket.emit('message', data);
        socket.broadcast.emit('message', data);
     });
});    

Client code:

<script>    
    var socket = io.connect('http://xy-app.rhcloud.com');

    socket.on('message', function(data) {
        $("#messages").prepend("<p>" + data.content + "</p>");
    }); 
</script>
1

1 Answers

-1
votes

Seems like You've configured your server in a wrong way by setting those configuration properties to values which you probably don't know. Have you read documentation? Do you know what is polling duration, heartbeat timeout and close timeout? Probably you've assigned incorrect values to these. You might want to do it like this and this would work:

io.configure(function () { 
io.set("polling duration", 30);
io.set("heartbeat timeout", 120);
io.set("heartbeat interval", 25);
io.set("close timeout", 120);

});