node.js - Socket.io connect event never fired -
i'm using nodejs , socket.io create socket server. problem is, on client , server, connect event never fired. code client this:
var socket = io.connect("http://127.0.0.1:8002"); console.log(socket); // works socket.on('connect', function(){ console.log('connected'); // not show meaning event not fired });
then, on server got:
var http = require('http'); var server = http.createserver().listen(8002); var io = require('socket.io').listen(server); var cookie_reader = require('cookie'); var querystring = require('querystring'); var redis = require('redis'); //configure socket.io store cookie set django io.use(function(){ io.set('authorization', function(data, accept){ if(data.headers.cookie){ data.cookie = cookie_reader.parse(data.headers.cookie); return accept(null, true); } return accept('error', false); }); // io.set('log level', 1); // io.set('origins', 'http://127.0.0.1:8001'); }); io.sockets.on('connection', function (socket) { console.log("someone connected"); // nothing shows // create redis client /*client = redis.createclient(); // subscribe redis events channel client.subscribe('notifications.' + socket.handshake.cookie['sessionid']); // grab message redis , send client client.on('message', function(channel, message){ console.log('on message', message); socket.send(message); }); // unsubscribe after disconnect event socket.on('disconnect', function () { client.unsubscribe('notifications.' + socket.handshake.cookie['sessionid']); });*/ });
i'm using this tutorial, if helps. i'm doing wrong?
unless need redis / django , other fancy stuff,
i suggest using started doc on socket.io's website:
Comments
Post a Comment