node.js - NodeJS + Socket.io : simple example working on local (Windows) but not on production (Centos) -


i'm trying simple example of nodejs , socket.io.

its work on local (windows)

but not working on production (centos 6.8)

what need change on production?

and should put app.js ?

(on local put app.js on project folder on production put on root folder *i put on root because node app.js cant run on project folder)

error on browser (looping until close browser)

http://www.domain.com/socket.io/eio=3&transport=polling&t=1470293560203-1 404 (not found) http://www.domain.com/socket.io/eio=3&transport=polling&t=1470293560203-2 404 (not found)

app.js

const util  = require('util'); const app   = require('express')(); const http  = require('http').server(app); const io    = require('socket.io')(http); const redis = require("redis");  const host = process.env.host || '0.0.0.0'; const port = process.env.port || 9090;  http.listen(port, host); util.log('listening @ http://' + host + ':' + port);  io.on('connection', function (socket) {    // util.log("connect");    var redisclient = redis.createclient();    redisclient.subscribe('notification');    redisclient.on('message', function (channel, message) {     util.log("new message in queue " + message + "channel");      message = json.parse(message);     // util.log(message.data.data.id);     socket.emit(channel, message.data);   });     socket.on('disconnect', function () {     redisclient.quit();   });  }); 

index.html

<div id="notifications"></div>  <script src="//cdn.socket.io/socket.io-1.3.5.js"></script> <script>   var socket = io('http://localhost:9090');    socket.on('message', function (msg) {     console.log(msg);      var notif = document.getelementbyid('notifications');      var div = document.createelement('div');      div.innerhtml = msg.name + '('+ msg.email +') registered';      notif.appendchild(div);   }); </script> 

so solved it.. bad.

first make sure express,redis,socket.io installed properly.

then @ index.html http://localhost:9090 must change http://domain.com:9090.


Comments