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 see nobody answered, so i'll post this, not sure if it'll help you:
var io = require('socket.io');
var server = http.createServer();
server.listen(8080, 'localhost');
var socket = io.listen(server);
basically just switch the calls to listen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With