samedi 12 mars 2016

socket.io not working on client side (transport error)

I am trying to implement sockets by following the tutorial http://ift.tt/1mHaJPj . I got node.js running, reddis working and port 3000 is listening. I can get console messages on command line. Problem occurs when i try to emit anything to the client side. Sever side:

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var Redis = require('ioredis');
var redis = new Redis();
redis.subscribe('test-channel', function(err, count) {
});
redis.on('message', function(channel, message) {
    console.log('Message Recieved: ' + message);
    message = JSON.parse(message);
    io.emit(channel + ':' + message.event, message.data);
});
http.listen(3000, function(){
    console.log('Listening on Port 3000');
});

Client side:

<script src="http://ift.tt/1Ki7F1r"></script>
<script>
    var socket = io('http://localhost:3000');
    //var socket = io('http://ift.tt/1Loei2F');
    socket.on("test-channel:App\\Events\\EventName", function(message){
        console.log("Working");
        // increase the power everytime we load test route
        $('#power').text(parseInt($('#power').text()) + parseInt(message.data.power));
    });

I tried to debug via browser console using "localStorage.debug = '*';" and I receive the following message:

engine.io-client:socket socket error {"type":"TransportError","description":{}} +4ms 
socket.io-client:manager connect_error +4ms 
socket.io-client:manager reconnect attempt error +1ms 
socket.io-client:manager will wait 5000ms before reconnect attempt +0ms 
engine.io-client:socket socket close with reason: "transport error" +1ms 
engine.io-client:polling transport not open - deferring close +1ms 
socket.io-client:manager attempting reconnect +5s 
socket.io-client:manager readyState closed +1ms

I tried all the available examples, I also tried the basic example from the socket.io website and nothing works. Any help is appreciated. Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire