1

I have simple nodejs server running using iisnode.

var app = require('http').createServer(handler);
var io = require('socket.io').listen(app);

io.configure(function () {
    io.set('transports', ['xhr-polling']);
    if (process.env.IISNODE_VERSION) {
        io.set('resource', '/nodejs/socket.io');
    }
});

function handler(req, res) {
    res.writeHead(200);
    res.end("Node JS is Running");
}

io.sockets.on('connection', function (socket) {
        console.log('a socket is connected');
    });

app.listen(process.env.PORT);

I want to talk to this socket from c# code (not javascript). I was running the nodejs server without iisnode before and the following code worked.

Client socket = new Client("somelink");
            socket.Error += SocketError;
            socket.On("connect", (fn) =>
                {
                    socket.Emit("new_order", 301);
                });

            socket.Connect();

But now I am running the server using iisnode and I cannot connect using the same code. I had to change my javascript code to connect to the server too.

from : =>

var socket = io.connect('somelink');

to: =>

 var socket = io.connect('somelink', {resource: 'nodejs/socket.io'});

My question is how do I change my c# code to connect to the nodejs server running on iisnode.

Client socket = new Client("somelink/nodejs/socket.io");

doesn't work. (handshake error)

dtksmsl
  • 239
  • 4
  • 14

1 Answers1

0

I am not sure how the Socket.io C# client works. But one thing you may be able to do on the server side to make the iisnode-hosted version behave exactly the same as a self-hosted one is to create a dedicated Web Site for the application as opposed to hosting it in IIS virtual directory. That way you will not need to customize the resource parameter when hosting in iisnode.

Tomasz Janczuk
  • 3,220
  • 21
  • 19
  • I used your tutorial to make the nodejs app run with iisnode in IIS virtual directory. I am pretty new at this. How do i go about creating a dedicated website? Any tips would be appreciated. – dtksmsl Oct 10 '13 at 13:53