爱米*阅

不是日志,不是剪切板

session 相关 - [技术 | Tech]

发布时间   2011-01-19 @ 14:29:00 标签    session java BSD C 编辑 | 分享 0

版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://www.blogbus.com/amixyue-logs/100483708.html

Anyway,近期用到的一点真枪实战的东西。

session,或称为 dialog or meeting or conversation,建立在 machine 或者 machine & user [被称为 login session] 之间,至少 4-tuple struct,还需要存储其它东西。

session,可以在 OSI [pysical layer | data layer | network layer | transport layer | Session layer | Presentation layer | Application layer ] 的 transport layer [如 tcp session ],或者 session layer[ 如 SIP Ip电话],或者 Application layer [如 Http session | telnet remote login session] 中实现。

session 建立在 internet socket 上,UC Beckley 在其上又提出了 BSD Socket 标准,目前很多操作系统,如 windows linux 都实现了这套标准。国内很多大学的 Unix 课程中,网络编程模块,都使用了 BSD socket。

BSD socket TCP:

server :

socket() init

bind() 绑定到 ip & port

listen()

accept()

send()

recv()

关注 accept():

once a tcp connection comes, the sever accept it , and create a child-process to cover this connection . so from the child-process , we can create session struct .

but if so, this connection is always on this server. But we can’t bind a connection to a certain machine . That means we can do following things:

1. use a flow control , or better called dispatcher, to dispatch connections to comparative free sub machine which process or dispatch;

when process, in order not to bind connection, this means to keep sever bindless , we’d better :

1) save session to another machine which is for session professionally , and return a sessionid; add sessionid to url, keep this sessionid always;

2)take the session to cookie;

but for security reason, should we also keep sth in server side & client side?

分享到: