Giter Site home page Giter Site logo

Comments (27)

aliw77 avatar aliw77 commented on June 27, 2024

Same issue - please help.

from session.socket.io.

eephillip avatar eephillip commented on June 27, 2024

Maybe because your not passing your secret key to the express session, they need to match I think.

edit
socket.io should be connecting because this module doesn't restrict the authorization, but session will be undefined unless the cookie was parsed correctly with your site key

...

var SITE_SECRET = 'key'

...

var cookieParser = express.cookieParser(SITE_SECRET)

...


//example express session
app.use(express.session({
    secret: SITE_SECRET,
    key: 'connect.sid',
    httpOnly: true,
    store: sessionStore
  }));

from session.socket.io.

wcamarao avatar wcamarao commented on June 27, 2024

That's not needed @eephillip, can you guys @githubpendosoft and @aliw77 copy and paste your output of npm ls?

from session.socket.io.

githubpendosoft avatar githubpendosoft commented on June 27, 2024

from session.socket.io.

wcamarao avatar wcamarao commented on June 27, 2024

That looks ok, however I reviewed your code and am not sure whether this is ok:

<script src='./node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js'></script>

Can you follow the instructions from socket.io docs on how to load the client?

from session.socket.io.

githubpendosoft avatar githubpendosoft commented on June 27, 2024

I'm afraid I can't.

After I've installed the socket.io with "npm install socket.io" how it is described on their site I have the socket.io.js in these fields only

./node_modules/socket.io/lib/socket.io.js
./node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js

And if I use the code from their example
<script src="/socket.io/socket.io.js"></script>
the script can't be loaded since it is absent on this path.

of course I can add some rewrite rules to htaccess but I think it will have the same affect as if I change the path to script.

.........
I've found the way how I can use almost their instructions how to connect the client
I can do it in such way
<script src='http://localhost:8080/socket.io/socket.io.js'>&lt;/script>
in this way the script socket.io.js is loaded well but I have the same session error:
connection ERR { error: 'could not look up session by key: connect.sid' }

May be it will work if I set up it to listen the port 80 but I can't do it since I have to have the Apache run on this port.

PS. sorry for my English.

from session.socket.io.

wcamarao avatar wcamarao commented on June 27, 2024

Yes, this is preferable

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

This should also be fine without hostname and port, assuming you're browsing within the same context. I just merged a pull request that will give you an error object with better tracing. It's published on npm as 0.1.4. Can you update it, try again and paste the stack trace?

from session.socket.io.

githubpendosoft avatar githubpendosoft commented on June 27, 2024

I've added the "handshake" data to log:

sessionSockets.on('connection', function (err, socket, session) {
console.log(socket.handshake);
console.log('connection ERR ', err);
console.log('connection session ', session);
});

So the output is:

info - socket.io started
debug - served static content /socket.io.js
debug - client authorized
info - handshake authorized rJxXIvLjXH2hHwwumLxT
debug - setting request GET /socket.io/1/websocket/rJxXIvLjXH2hHwwumLxT
debug - set heartbeat interval for client rJxXIvLjXH2hHwwumLxT
debug - client authorized for
debug - websocket writing 1::
{ headers:
{ host: 'localhost:8080',
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0',
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8',
'accept-language': 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
'accept-encoding': 'gzip, deflate',
referer: 'http://localhost/comet/',
origin: 'http://localhost',
connection: 'keep-alive' },
address: { address: '127.0.0.1', port: 42470 },
time: 'Sat Jan 26 2013 15:23:15 GMT+0400 (MSK)',
query: { t: '1359199395077' },
url: '/socket.io/1/?t=1359199395077',
xdomain: true,
secure: undefined,
secret: 'key',
cookies: {},
signedCookies: {} }
connection ERR [Error: could not look up session by key: connect.sid]
connection session undefined

from session.socket.io.

quiricada avatar quiricada commented on June 27, 2024

same problem here.

so i tried other packages, the same problem.

like githubpendosoft, the cookies were empty/null. then i came across this socketio/socket.io#776, yipingshui's comment on 'use io.connect("http://ip:port")', bingo!

my original: io.connect("http://192.168.10.1:2222")
changed it to: io.connect("http://localhost:2222")

newbie here, my guess:

  1. the connect.sid cookie was under "localhost"
  2. my hosts file didn't have a mapping for 192.168.10.1 localhost

from session.socket.io.

wcamarao avatar wcamarao commented on June 27, 2024

Thanks quiricada. Can you githubpendosoft follow up on that and let us know if you make any progress? It doesn't look like you're doing something wrong with session.socket.io, it seems to be something with your socket.io config.

from session.socket.io.

githubpendosoft avatar githubpendosoft commented on June 27, 2024

I've used io.connect('http://localhost:8008'); as you can see in the code I've posted above.
I've opened the same URL in the browser 'http://localhost/comet/'.
I've tried to move the index.php to www root and open in the browser 'http://localhost/index.php'.

I've got the same error:

info - socket.io started
debug - served static content /socket.io.js
debug - client authorized
info - handshake authorized G0eABh_2A2512Pmzleqr
debug - setting request GET /socket.io/1/websocket/G0eABh_2A2512Pmzleqr
debug - set heartbeat interval for client G0eABh_2A2512Pmzleqr
debug - client authorized for
debug - websocket writing 1::
{ headers:
{ host: 'localhost:8080',
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0',
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8',
'accept-language': 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
'accept-encoding': 'gzip, deflate',
referer: 'http://localhost/index.php',
origin: 'http://localhost',
connection: 'keep-alive' },
address: { address: '127.0.0.1', port: 46136 },
time: 'Mon Jan 28 2013 23:15:45 GMT+0400 (MSK)',
query: { t: '1359400545556' },
url: '/socket.io/1/?t=1359400545556',
xdomain: true,
secure: undefined,
secret: 'key',
cookies: {},
signedCookies: {} }
connection ERR [Error: could not look up session by key: connect.sid]
connection session undefined

The code
server: http://myxomop.e-vds.ru/node/app2.js
client: http://myxomop.e-vds.ru/node/index.php.txt

I will try to test it on real domain and let you know in 1-2 days.

from session.socket.io.

wcamarao avatar wcamarao commented on June 27, 2024

Wait, you're using socket.io with php on apache? This library won't help you. It integrates socket.io with either connect or express which are node modules.

from session.socket.io.

githubpendosoft avatar githubpendosoft commented on June 27, 2024

I'm use socket.io with nodejs server.
The Apache was used to handle the client code only.

It doesn't working without Apache as well. Please check my code. Is it correct?

server: http://myxomop.e-vds.ru/node/app2.js
client: http://myxomop.e-vds.ru/node/index.html

Could you please provide me with en example that is working?

BR.

from session.socket.io.

wcamarao avatar wcamarao commented on June 27, 2024

Ok, I wrote one quickly, doing the minimum to demo the features: read and write session values within sockets. It's under /example. You will need to do npm install & node server.js, then go to localhost:3000. Hope that helps.

from session.socket.io.

bjwyse avatar bjwyse commented on June 27, 2024

Absolutely great module. Thanks for writing it. I am up and running now.

I had some issues with session being undefined and it was because on client side I connected using 'http://127.0.0.1:3000' but had browsed to 'http://localhost:3000'.

Error was '{}'. It would be cool if you could detect this issue and report it in err.

from session.socket.io.

wcamarao avatar wcamarao commented on June 27, 2024

Thanks for your feedback bjwyse. That's a common mistake when getting started with socket.io, and you can avoid that by simply calling io.connect() without an address.

from session.socket.io.

MaxMarkson avatar MaxMarkson commented on June 27, 2024

Hi, I'm still having this problem.
The client's connection is made in this way:

<script type="text/javascript">socket = io.connect('http://'+location.host);</script>

so it can't be the same problem of bjwyse.
Any suggestion?

from session.socket.io.

wcamarao avatar wcamarao commented on June 27, 2024

@MaxMarkson can you try the example and see if that works out there?

https://github.com/functioncallback/session.socket.io/tree/master/example

from session.socket.io.

MaxMarkson avatar MaxMarkson commented on June 27, 2024

When I try the example I have this error:
"TypeError: Property 'engine' of object # is not a function
at View.render (C:\Users\Massimo\workspace\Example\node_modules\express\lib\view.js:75:8)
at Function.app.render (C:\Users\Massimo\workspace\Example\node_modules\express\lib\application.js:501:10)
at ServerResponse.res.render (C:\Users\Massimo\workspace\Example\node_modules\express\lib\response.js:755:7)
at sessionSockets.on.socket.on.session.foo (C:\Users\Massimo\workspace\Example\example.js:29:7)
at callbacks (C:\Users\Massimo\workspace\Example\node_modules\express\lib\router\index.js:161:37)
at param (C:\Users\Massimo\workspace\Example\node_modules\express\lib\router\index.js:135:11)
at pass (C:\Users\Massimo\workspace\Example\node_modules\express\lib\router\index.js:142:5)
at Router._dispatch (C:\Users\Massimo\workspace\Example\node_modules\express\lib\router\index.js:170:5)
at Object.router (C:\Users\Massimo\workspace\Example\node_modules\express\lib\router\index.js:33:10)
at next (C:\Users\Massimo\workspace\Example\node_modules\connect\lib\proto.js:190:15)"

But I don't have to use the express module, I need an integration between connect, connect-route, socket.io and passport.
Here my little example which has the "[Error: could not look up session by key: connect.sid]" error: http://pastebin.com/mNDZyjpa

from session.socket.io.

MaxMarkson avatar MaxMarkson commented on June 27, 2024

@functioncallback have you got any news about the problem?

from session.socket.io.

wcamarao avatar wcamarao commented on June 27, 2024

@MaxMarkson I don't see any problem really. I have a more complete working example here: https://github.com/functioncallback/upstream

Take a look and see if that helps maybe? At least passport is being used, with express, socket.io and other modules. Also, it's deployed here: http://upstream-beta.herokuapp.com

from session.socket.io.

alexand7u avatar alexand7u commented on June 27, 2024

This error "could not look up session by key: connect.sid" appeared only in chrome(but not every time to fix you have to restart the browser ), firefox works ok.
the only thing i did was to invert server.listen with sessionSockets.on('connection',function(){ ...});
P.S: I tested session.socket.io example from git and still the same issue, is some timeout problem, the session remain saved or something like this

from session.socket.io.

MaxMarkson avatar MaxMarkson commented on June 27, 2024

Well, I have the problem even with firefox and the server.listen was already after the on connection.
The last solution must be something wrong somewhere else in my code, i don't know what else can be...apparently no one has my problem.

from session.socket.io.

hugogz avatar hugogz commented on June 27, 2024

Hello!

first of all thanks for this great code, but i've been with a problem for some hours and i guess maybe you can help me with it..

I'm a newie with nodejs and express, this is my server code (i got it from the sample):

var http = require('http')
, path = require('path')
, connect = require('connect')
, express = require('express')
, app = express();

var cookieParser = express.cookieParser('aaaa')
, sessionStore = new connect.middleware.session.MemoryStore();

app.configure(function () {
console.log("hola configuracion "+sessionStore);
app.set('views', path.resolve('views'));
app.set('view engine', 'jade');

app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(cookieParser);
app.use(express.session({ store: sessionStore }));
app.use(app.router);
});

var server = http.createServer(app)
, io = require('socket.io').listen(server);

var SessionSockets = require('session.socket.io')
, sessionSockets = new SessionSockets(io, sessionStore, cookieParser);

app.get('/', function(req, res) {
console.log("hola get "+session);
req.session.foo = req.session.foo || 'bar';
console.log("hola get "+session);
res.render('index');
});

sessionSockets.on('connection', function (err, socket, session) {
console.log("hola emit "+err);
console.log("hola emit "+session);
socket.emit('session', session);

socket.on('foo', function(value) {
// foo = value;
console.log("hola log "+session);
console.log("hola log0 "+value);
session.foo = value;
console.log("hola log2"+session);
session.save();
console.log("hola log3"+session);
socket.emit('session', session);
});
});

server.listen(3000);

and this is the client code:

<script type='text/javascript' src='socket.io.js'> </script> <style> body { padding: 30px 50px; }
  #t {
    display: block;
    margin-bottom: 15px;
    outline: none;
    width: 700px;
    height: 100px;
  }

  #foo {
    width: 200px;
  }
</style>
</head>

SessionSockets usage example

<textarea id="t"></textarea>
<textarea id="foo"></textarea>

<script type='text/javascript'>
  var socket = io.connect("http://localhost:3000");

  socket.on('session', function (session) {
    document.getElementById('t').value = JSON.stringify(session);
  });

  document.getElementById('foo').addEventListener('keyup', function () {
    socket.emit('foo', this.value);
  });
</script>
</body>

The problem is that the session is always null when it reachs the server. The error that comes with it is "Error: could not look up session by key: connect.sid"

I think i had it working one time but after i can't configure it to do it. I'm getting crazy with this error and i can't find a solution. Any help will be much apreciated,

Thanks in advance!

Hugo.

from session.socket.io.

S0c5 avatar S0c5 commented on June 27, 2024

Hi :) i have the same problem :( :D

from session.socket.io.

aleks091 avatar aleks091 commented on June 27, 2024

Hi, I had the same problem as bjwyse, and his solution worked for me

from session.socket.io.

totty90 avatar totty90 commented on June 27, 2024

Same problem with express4 and all new deps.

from session.socket.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.