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>