English 中文(简体)
node.js / socket.io, cookies only working local
原标题:node.js / socket.io, cookies only working locally

我试图利用基于厨师的课,但只占用当地机器的工作,而不是网络。 但是,如果我取消会议的相关内容,它将在网络上发挥巨大作用。

你们不得不放弃这里缺乏质量法,而我刚刚从 no/ocket等开始,找到任何明确的指南是艰难的,因此,现在就在N00b领土上的我太平。 基本上,迄今为止,这同各种幻灯片一道,对我实际做些什么有大约10%的理解。

我在 Chrome中看到的错误是:

页: 1 500(因特网服务器Error)

页: 1

页: 1

页: 1

页: 1

www.un.org/chinese/sc/presidency.asp

j Query.extendy.ready --United Nations jquery.js:438

在服务器专栏中,见:

debug - 符合静态内容。

减员——授权

warn - handshake error No cookie

我的服务器是:

var express = require( express )
  , app = express.createServer()
  , io = require( socket.io ).listen(app)
  , connect = require( express/node_modules/connect )
  , parseCookie = connect.utils.parseCookie
  , RedisStore = require( connect-redis )(express)
  , sessionStore = new RedisStore();

app.listen(8080,  192.168.0.6 );

app.configure(function()
{
    app.use(express.cookieParser());

    app.use(express.session(
    {
        secret:  YOURSOOPERSEKRITKEY ,
        store: sessionStore
    }));
});

io.configure(function()
{
    io.set( authorization , function(data, callback)
    {
        if(data.headers.cookie)
        {
            var cookie = parseCookie(data.headers.cookie);

            sessionStore.get(cookie[ connect.sid ], function(err, session)
            {
                if(err || !session)
                {
                    callback( Error , false);
                }
                else
                {
                    data.session = session;
                    callback(null, true);
                }
            });
        }
        else
        {
            callback( No cookie , false);
        }
    });
});

var users_count = 0;

io.sockets.on( connection , function (socket)
{
    console.log( New Connection );

    var session = socket.handshake.session;

    ++users_count;

    io.sockets.emit( users_count , users_count);

    socket.on( something , function(data)
    {
        io.sockets.emit( doing_something , data[ data ]);
    });


    socket.on( disconnect , function()
    {
        --users_count;

        io.sockets.emit( users_count , users_count);
    });

});

我的一页联合材料是:

jQuery(function($){

    var socket = io.connect( http://192.168.0.6 , { port: 8080 } );

    socket.on( users_count , function(data)
    {
        $( #client_count ).text(data);
    });

    socket.on( doing_something , function(data)
    {
        if(data ==   )
        {
            window.setTimeout(function()
            {
                $( #target ).text(data);
            }, 3000);
        }
        else
        {
            $( #target ).text(data);
        }
    });

    $( #textbox ).keydown(function()
    {
        socket.emit( something , { data:  typing  });
    });

    $( #textbox ).keyup(function()
    {
        socket.emit( something , { data:    });
    });

});
问题回答

如果服务器和客户有不同的 clo锁,则 co子在安装后可能立即到期。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签