The invention provides an instant data transmission method level system based on websocket protocol and HTTP protocol. The method includes: establishing the connection between the front HTML5 and the websocket server, pushing the websocket data to the front end HTML5 user based on the websocket server, and the event trigger mechanism of the front end HTML5 to repeat the websocket data. After filtering, the filtered data is displayed to the user, and the front end HTML5 detects whether the new websocket data is accepted in the preset time, if then, the new websocket data is accepted, if not, the execution of the HTTP request to verify the data set is correct. If, then, use the websocket protocol to transmit the data, if not, if not, Executes the HTTP protocol to get the data, determines whether the check is finished or not, if so, executes the HTTP request to call the end data. The invention can solve the problem of inconsistency between front and rear ends of messages, and solve the problem of wasting resources and transmitting long delay time when transmitting real-time data.
【技术实现步骤摘要】
一种基于websocket协议与http协议的即时数据传输方法及系统
本专利技术属于及时数据通信
,尤其涉及一种基于websocket协议与http协议的即时数据传输方法及系统。
技术介绍
现有的即时数据通信主要单独通过websocket协议传输数据,或者单独通过http协议轮询传输消息,因此,在单独使用websocket协议时,websocket在建立连接的过程中收不到消息,导致消息前后端不一致,存在严重的缺陷问题,而在单独使用http轮询的情况下,不仅浪费资源开销,而且数据传输延迟时间较长。因此,如何在即时数据传输时既解决消息前后端不一致,又解决资源开销浪费、输出传输延迟时间较长,是一项亟待解决的问题。
技术实现思路
有鉴于此,本专利技术提供了一种基于websocket协议与http协议的即时数据传输方法,能够在即时数据传输时既解决消息前后端不一致,又解决资源开销浪费、输出传输延迟时间较长的问题。为了实现上述目的,本专利技术提供如下技术方案:一种基于websocket协议与http协议的即时数据传输方法,包括:建立前端html5与websocket服务器之间的连接;基于所述websocket服务器推送websocket数据到所述前端html5用户;所述前端html5采用事件触发机制,对重复websocket数据进行过滤处理,将过滤后的数据显示给所述用户;所述前端html5检测预设时间内是否接受到新的websocket数据,若是,则接受所述新的websocket数据,若否,则:执行http请求校验数据集合是否正确,若是,则使用websocket协议传输 ...
【技术保护点】
一种基于websocket协议与http协议的即时数据传输方法,其特征在于,包括:建立前端html5与websocket服务器之间的连接;基于所述websocket服务器推送websocket数据到所述前端html5用户;所述前端html5采用事件触发机制,对重复websocket数据进行过滤处理,将过滤后的数据显示给所述用户;所述前端html5检测预设时间内是否接受到新的websocket数据,若是,则接受所述新的websocket数据,若否,则:执行http请求校验数据集合是否正确,若是,则使用websocket协议传输数据,若否,则:执行http协议获取数据;判断校验是否结束,若是,则执行http请求调用结束数据。
【技术特征摘要】
1.一种基于websocket协议与http协议的即时数据传输方法,其特征在于,包括:建立前端html5与websocket服务器之间的连接;基于所述websocket服务器推送websocket数据到所述前端html5用户;所述前端html5采用事件触发机制,对重复websocket数据进行过滤处理,将过滤后的数据显示给所述用户;所述前端html5检测预设时间内是否接受到新的websocket数据,若是,则接受所述新的websocket数据,若否,则:执行http请求校验数据集合是否正确,若是,则使用websocket协议传输数据,若否,则:执行http协议获取数据;判断校验是否结束,若是,则执行http请求调用结束数据。2.根据权利要求1所述的方法,其特征在于,所述基于所述websocket服务器推送websocket数据到所述前端html5用户包括:所述websocket服务器将所述websocket数据封装成json数据;基于websocket协议或http协议将所述json数据传输至所述前端html5用户。3.根据权利要求1所述的方法,其特征在于,所述前端html5采用事件触发机制,对重复websocket数据进行过滤处理,将过滤后的数据显示给所述用户包括:所述前端html5按照json的key-value形式触发事件,采用数据集合缓存去重方式对重复websocket数据进行过滤处理,将过滤后的数据显示给所述用户。4.根据权利要求1所述的方法,其特征在于,所述执行http请求调用结束数据后,还包括:基于所述websocket服务器推送全局消息数据到所述前端html5用户。5.根据权利要求1所述的方法,其特征在于,所述预设时间为1.5秒。6.一种基于websocket协议与http协议的即时数据传输系统,其特征在于,...
【专利技术属性】
技术研发人员:李杰,何隽,
申请(专利权)人:北京焦点新干线信息技术有限公司,
类型:发明
国别省市:北京,11
还没有人留言评论。发表了对其他浏览者有用的留言会获得科技券。