tjanczuk / iisnode

Hosting node.js applications in IIS on Windows
Other
1.86k stars 587 forks source link

Client address metadata is lost when hosting socket.io on iisnode #397

Open ja67 opened 9 years ago

ja67 commented 9 years ago

Hi,

I am using iisnode to host Etherpad, where socket.io is responsible for communication between server and client browser. I found the there are errors during handshake between server and client that the address of client is undefined.

To figure out the reason, I wrote a script and test socket.io 0.9.17 module independently:

// JavaScript source code
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io');
var times = 0;
app.get('/', function (req, res) {
    res.send("<!DOCTYPE html>" +
    '<html lang="en" xmlns="http://www.w3.org/1999/xhtml">' +
'<head>' +
    '<meta charset="utf-8" />' +
    '<title>Socket.IO Test</title>' +
    '<script src="/socket.io/socket.io.js"></script>' +
    '<script>' +
  'var socket = io.connect("http://localhost:8080");\n' +
  'socket.emit("test");'+
    '</script>' +
'</head>' +
'<body>' +
times +
'</body>' +
'</html>;')
});

var socketio = io.listen(http);
socketio.set("transports",["xhr-polling"]);
socketio.sockets.on('connection', function (socket) {
times += 1;
console.log('a user connected');
 console.dir(socket.handshake);
});
socketio.sockets.on("test",function(socket)
{
     console.log('test event triggered!');
     console.dir(socket.handshake);
});

http.listen(process.env.PORT||8080, function () {
    console.log('listening on *:' + process.env.PORT||8080);
});

and I tried both running node.js with the script directly and hosting it on iis, setting the port of iis site to be 8080. After comparing the log file of these two approach, I found the "address" value of socket.handshake is always undefined when running on iisnode.

I was wondering if these might be caused by the named pipe technique of iisnode and if this is unavoidable. Thanks!

queequac commented 9 years ago

In general socket.io can also run in iisnode. Guess the problem resides in your web.config. Would you share it?