websocket关于客户端合法性的问题

WBOY
Release: 2016-06-06 20:29:17
Original
1347 people have browsed it

近期在搞个websocket的项目,由于初次弄,很多东西不理解,所以想咨询个问题,就是:如果很多客户端链接上来了,那么我该怎么验证这个客户端的合法性呢?我看了握手协议部分,好像并不能做什么。求大神指导,谢谢。

回复内容:

近期在搞个websocket的项目,由于初次弄,很多东西不理解,所以想咨询个问题,就是:如果很多客户端链接上来了,那么我该怎么验证这个客户端的合法性呢?我看了握手协议部分,好像并不能做什么。求大神指导,谢谢。

没做过,要我做可能会这样:
1、创建socket连接时要求发送一次当前站点的标识cookie信息 例如 PHPSESSID 。
2、如果这个用户是登陆的,web服务器会记录这个用户的session(例如数据库或者缓存中),socket服务器去同一处验证下session是否存在就行了,或者调用接口方式。

把用户的sessionidsend到服务端,服务端根据这个sessionid去磁盘或者存储读取session数据,就知道用户是否登录,是谁了

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!