Trying to Implement Node.js and Socket.io on dedicated server -


recently, have been experimenting node.js , socket.io. successfully, have been able implement these on localhost. use functionality on dedicated server. hosting server own home , cannot node , socket run outside of localhost. importance of can use 2 different computers while testing out site. here code follows:

app.js:     var app = require('express')()   , server = require('http').createserver(app)   , io = require('socket.io').listen(server);  server.listen(80);  app.get('/', function (req, res) {   res.sendfile(__dirname + '/index.html'); });  io.sockets.on('connection', function (socket) {   socket.emit('news', { hello: 'world' });   socket.on('my other event', function (data) {     console.log(data);   }); }); 

index.html:      <script src="http://localhost:8080/socket.io/socket.io.js"></script>     <script>       var socket = io.connect('http://localhost:8080');       socket.on('news', function (data) {         console.log(data);         socket.emit('my other event', { my: 'data' });       });  </script> 

these samples taken directly off socket.io site. works on localhost, not externally. cannot use on computer. advised change

var socket = io.connect('http://localhost:8080');
var socket = io.connect('http://mydomain.com:8080');
, makes browser throw following errors :

 uncaught referenceerror: io not defined mydomain.com/:3     http://mydomain.com/socket.io/socket.io.js  mydomain.com/:1 

even on main server computer. im using osx server mac mini btw.

any advice appreciated:

it looks you're listening on port 80 instead of 8080, , need point script block server, try

<script src="http://localhost:8080/socket.io/socket.io.js"></script> 

needs be

<script src="http://mydomain.com:80/socket.io/socket.io.js"></script> 

or better yet

<script src="/socket.io/socket.io.js"></script> 

if doesn't work, make sure check errors under network tab of debugger window (presuming you're using chrome) make sure you're loading socket.io.js file correctly.


Comments

Popular posts from this blog

Using 'OR' and 'AND' in SQL Server -

python - Finding intersection between ellipse and a line -

c++ - NetBeans Remote Development with additional configuration -