I have a windows server running IIS and node.js with socket.io for an interactive whiteboard application I am developing. I want both the IIS website and node.js server to listen on port 80, but be bound to different IP addresses.
From what I can find, socket.io doesn’t have the ability to specify ip address. This limitation can supposedly be overcome by creating an http server instance. I’m new to socket.io and node.js and am a little lost trying to do this. I’ll include the original server code (that listens on a specific port) and my attempt to instantiate a server on a specific IP address.
Original
(function() {
var io;
io = require('socket.io').listen(80);
io.sockets.on('connection', function(socket) {
socket.on('drawClick', function(data) {
socket.broadcast.emit('draw', {
x: data.x,
y: data.y,
type: data.type
});
});
});
}).call(this);
Modified
(function() {
var host = "10.70.254.76";
var port = 80;
var http = require("http").createServer();
var io = require("socket.io").listen(http);
http.listen(port, host);
io.sockets.on('connection', function(socket) {
socket.on('drawClick', function(data) {
socket.broadcast.emit('draw', {
x: data.x,
y: data.y,
type: data.type
});
});
});
}).call(this);
I get Error: listen EACCES when starting the modified code
I got it!
The problem actually lies with IIS and it’s socket pooling behavior. IIS automatically reserves port 80 for all IP addresses (even if they are not currently bound to a site).
What I had to do was use the netsh command to override the default bindings and bind ip addresses via the netsh command.
Here’s what I did. This solution works for IIS 7 in Windows Server 2008 R2.
In my case I only have one active website being served by IIS and only had one IP bound to it. This freed up my secondary IP address for node to listen on it and port 80.