urbz
urbz

Reputation: 2667

Socket.io + Azure web sockets issue

I am working on a multiplayer chess game with NodeJS and socket.IO.

I have problem hosting it on Azure tho.. I tried many different approaches, a few mentioned:

Forcing the application to only use WebSockets by adding the code below:

io.configure(function() {
  io.set('transports', ['websocket']);
}); 

Added <webSocket enabled="false"/> in web.config file..

Note: This disables the IIS WebSockets module, which includes its own implementation of WebSockets and conflicts with Node.js specific WebSocket modules such as Socket.IO. If this line is not present, or is set to true, this may be the reason that the WebSocket transport is not working for your application.

Matching origin protocol to ensure no SSL issues.

io.configure(function() {
  io.set('match origin protocol', true);
});

I now started from scratch, since I thought my server-side part was corrupt, and tried Socket.io chat example instead.

enter image description here


STILL THE SAME ERROR! See picture below.

enter image description here

Anyone? I am unsure if it's a client-side or server-side issue. It seems like it's trying to XHR-poll instead of using web sockets..

Thanks in advance.

Upvotes: 2

Views: 3056

Answers (1)

urbz
urbz

Reputation: 2667

I got it working, thank you Chris Anderson-MSFT for your help.

The weird thing that occurred for me when deploying with FTP was that my node_modules folder differed with version(s) specified in my package.json.

I solved this by connecting my web app on Azure to a local Git repository and deploying the app through git. This connects my packages recursively and matches correct versions.

I also needed to enforce my client-side socket-io to use web sockets by specifying transport method:

var socket = io({transports:['websocket']});

And this is what my server-side file ended up looking like:

var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var port = process.env.PORT || 3000;
app.use(express.static('public'));

app.get('/', function(req, res) {
 res.sendFile(__dirname + '/public/default.html');
});

io.on('connection', function(socket) {
    io.set('transports', ['websocket']);
    console.log('new connection on socket.io');
    socket.on('move', function(msg) {
        socket.broadcast.emit('move', msg);
    });
});

server.listen(port, function () {
  console.log('Server listening at port %d', port);
});

Upvotes: 3

Related Questions