mercredi 16 mars 2016

NodeJs not able to listen to port on digital ocean Ubuntu

I am trying to implement messaging on my server .Which is Ubuntu 14.04/Nginx

I have installed

1.nodejs 
2.Redis
3.laravel 

all successfully

when I run command

node -v

its giving me the version of node

in my controller my code look like this

public function sendMessage(){

        $redis = LRedis::connection();
        $redis->publish('message', 'Sending Message to Port');
        return redirect('writemessage');
    }

and my server.js code is like this

var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var redis = require('redis');

server.listen(8890);
io.on('connection', function (socket) {

  console.log("new client connected");
  var redisClient = redis.createClient();
  redisClient.subscribe('message');

  redisClient.on("message", function(channel, message) {
    console.log("mew message in queue "+ message + "channel");
    socket.emit(channel, message);
  });

  socket.on('disconnect', function() {
    redisClient.quit();
  });

});

The Redis server is running on default 6379

and to listen to listen to the broadcast my socket.php file has following code

<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="http://ift.tt/1Abvuox"></script>

    <script>
        var socket = io.connect('http://localhost:8890');
        socket.on('message', function (data) {
            $( "#messages" ).append( "<p>"+data+"</p>" );
          });
    </script>

Everything is running fine but I don't see any message on the socket.php page

Any Idea how to debug this

the same works fine on Localhost



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire