由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Node.js question on identifying 2 different web browser tab/pages
相关主题
现在怎么越来越多的公司用cookie了?这不是过时的技術吗?写个简单的聊天server
走mobile 和走backend的优劣是什么大家从server push数据到client side,用啥办法好些?
Web Service怎么让多个api call share 同一个 connection ??把我的Admin Tool彻底port到Web上了 (转载)
How to update button status from node.js server ?.NET对马工还有就业前途吗?
拿C*当message queue用,不知道哪里面试能通过nodejs到底有啥好的?大牛给解释解释?
Principal Software Engineer,还是Architect?前端为什么不用java写
javascript function-ask for helpGo真的很有意思吗?
HTML5 Hackspython 2/python 3这是怎么一回事呀
相关话题的讨论汇总
话题: req话题: session话题: backend话题: different话题: browser
进入Programming版参与讨论
1 (共1页)
s*****w
发帖数: 1527
1
This is the flow,
web client <--> Node server <--> backend program
i could have 2 different browse tabs for the same URL,
in the 1st one i click "send me info A from backend",
in 2nd webpage i click "send me info B from backend".
Now how do i distinguish A and B in the node.js ?
Was looking for sample for session/cookie, just cannot find the right sample.
Thanks very much !
p*****2
发帖数: 21240
2
stateless吧?
s*****w
发帖数: 1527
3
大牛请多展展,我是刚开始学node。
最土的方法据说是每个session开一个socket,然后node server根据socket handle来
区分。
但我想总有现成简单的方法吧。
谢谢!

【在 p*****2 的大作中提到】
: stateless吧?
l**********n
发帖数: 8443
4
一个session可以开n个socket.
甚至一个page可以开多个websocket.
不同的socket干不同的事情

【在 s*****w 的大作中提到】
: 大牛请多展展,我是刚开始学node。
: 最土的方法据说是每个session开一个socket,然后node server根据socket handle来
: 区分。
: 但我想总有现成简单的方法吧。
: 谢谢!

l**********n
发帖数: 8443
5
只是不明白你为什么要用socket?
s*****w
发帖数: 1527
6
大牛有没有更简单的办法?

【在 l**********n 的大作中提到】
: 一个session可以开n个socket.
: 甚至一个page可以开多个websocket.
: 不同的socket干不同的事情

s*****w
发帖数: 1527
7
不会做啊,就听别人说了

【在 l**********n 的大作中提到】
: 只是不明白你为什么要用socket?
l**********n
发帖数: 8443
8
筒单的吧?用query url.

【在 s*****w 的大作中提到】
: 大牛有没有更简单的办法?
s*****w
发帖数: 1527
9
我什么都不会,:(
能给我写一段吗?伪币答谢。。。

【在 l**********n 的大作中提到】
: 筒单的吧?用query url.
l**********n
发帖数: 8443
10
like this:
?page=page1
?page=page2
on server side:
switch(req.query.page){
case 'page1':break;
case 'page2':break;
default:break;
}

【在 s*****w 的大作中提到】
: 我什么都不会,:(
: 能给我写一段吗?伪币答谢。。。

相关主题
Principal Software Engineer,还是Architect?写个简单的聊天server
javascript function-ask for help大家从server push数据到client side,用啥办法好些?
HTML5 Hacks把我的Admin Tool彻底port到Web上了 (转载)
进入Programming版参与讨论
s*****w
发帖数: 1527
11
可能我没说清楚,
2个web browser 都可以同时打开page1的,你这个可以区分吗?
谢谢!

【在 l**********n 的大作中提到】
: like this:
: ?page=page1
: ?page=page2
: on server side:
: switch(req.query.page){
: case 'page1':break;
: case 'page2':break;
: default:break;
: }

l**********n
发帖数: 8443
12
two different browsers could share the same session ID, or have different
sessions. if you open two pages in the same browser, they will have the
session ID.
on the server side, they belong to two different sessions.

【在 s*****w 的大作中提到】
: 可能我没说清楚,
: 2个web browser 都可以同时打开page1的,你这个可以区分吗?
: 谢谢!

s*****w
发帖数: 1527
13
if i open 2 pages in the same browser,
in 1st page i click "button A",
in 2nd i click "button B".
if there have the same session ID, how can i distinguish them ?
(for our backend, there's only 1 pipe from web server to backend, when i get
data back, i need to know where to send the result to ...)

【在 l**********n 的大作中提到】
: two different browsers could share the same session ID, or have different
: sessions. if you open two pages in the same browser, they will have the
: session ID.
: on the server side, they belong to two different sessions.

b********0
发帖数: 62
14
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end("");
}).listen(8080);
函数里不是这个req res成对的么 根据req给res返回就行了啊 不会混的啊
如果是要区分用户的话
response.writeHead(200, {
'Set-Cookie': 'key=value',
'Content-Type': 'text/plain'
});
不同的用户给个不同的value就行了 然后parse req就可以区分用户了
s*****w
发帖数: 1527
15
先容我理解一下,谢谢了!

【在 b********0 的大作中提到】
: http.createServer(function (req, res) {
: res.writeHead(200, {'Content-Type': 'text/plain'});
: res.end("");
: }).listen(8080);
: 函数里不是这个req res成对的么 根据req给res返回就行了啊 不会混的啊
: 如果是要区分用户的话
: response.writeHead(200, {
: 'Set-Cookie': 'key=value',
: 'Content-Type': 'text/plain'
: });

d****n
发帖数: 1637
16
generate uuid in cookie if not exists
https://github.com/broofa/node-uuid
uuid will be bound with cookie and in your request object.
bind some information for each uuid then you will know what the page state
is.

sample.

【在 s*****w 的大作中提到】
: This is the flow,
: web client <--> Node server <--> backend program
: i could have 2 different browse tabs for the same URL,
: in the 1st one i click "send me info A from backend",
: in 2nd webpage i click "send me info B from backend".
: Now how do i distinguish A and B in the node.js ?
: Was looking for sample for session/cookie, just cannot find the right sample.
: Thanks very much !

s*****w
发帖数: 1527
17
非常谢谢,让我去学习一下。

【在 d****n 的大作中提到】
: generate uuid in cookie if not exists
: https://github.com/broofa/node-uuid
: uuid will be bound with cookie and in your request object.
: bind some information for each uuid then you will know what the page state
: is.
:
: sample.

j******f
发帖数: 825
18
这个用socketio应该很容易
s*****w
发帖数: 1527
19
Can dryden and other big cow help me to complete this,
Thanks very much !
var express = require("express");
var session = require("express-session");
var app = express();
//Creating Router() object
var router = express.Router();
// Router middleware, mentioned it before defining routes.
router.use(function(req,res,next) {
console.log("/" + req.method);
next();
});
router.use("/user/:id",function(req,res,next){
console.log(req.params.id)
if(req.params.id == 0) {
res.json({"message" : "You must pass ID other than 0"});
}
else next();
});
// Provide all routes here, this is for Home page.
router.get("/",function(req,res){
res.json({"message" : "Hello World"});
});
router.get("/user/:id",function(req,res){
res.json({"message" : "Hello "+req.params.id});
});
// Tell express to use this router with /api before.
// You can put just '/' if you don't want any sub path before routes.
app.use("/api",router);
app.use( session( {
genid: function(req)
{
return genuuid()
},
secret: 'keyboard cat',
resave: false,
saveUninitialized: true
} ));
// Listen to this Port
app.listen(8888,function(){
console.log("Live at Port 8888");
});

【在 d****n 的大作中提到】
: generate uuid in cookie if not exists
: https://github.com/broofa/node-uuid
: uuid will be bound with cookie and in your request object.
: bind some information for each uuid then you will know what the page state
: is.
:
: sample.

1 (共1页)
进入Programming版参与讨论
相关主题
python 2/python 3这是怎么一回事呀拿C*当message queue用,不知道哪里面试能通过
现在最成熟稳定的websocket server是什么?Principal Software Engineer,还是Architect?
请教一个Node.js的疑惑javascript function-ask for help
这个表怎么理解HTML5 Hacks
现在怎么越来越多的公司用cookie了?这不是过时的技術吗?写个简单的聊天server
走mobile 和走backend的优劣是什么大家从server push数据到client side,用啥办法好些?
Web Service怎么让多个api call share 同一个 connection ??把我的Admin Tool彻底port到Web上了 (转载)
How to update button status from node.js server ?.NET对马工还有就业前途吗?
相关话题的讨论汇总
话题: req话题: session话题: backend话题: different话题: browser