Home > Web Front-end > H5 Tutorial > body text

怎样自定义并使用websocket子协议?

WBOY
Release: 2016-06-07 08:44:38
Original
2975 people have browsed it

从websocket API 中了解到,websocket 可以自定义子协议,想深入了解一下,但是好像网上并没有类似的例子,请高手指点。

回复内容:

subprotocol 不过是 header 里的一个字段而已。

RFC 6455 - The WebSocket Protocol
The WebSocket API 由于Websocket协议提供的是一个基于包的可靠传输协议,它并不像HTTP那样是个应用协议,它的包对内容并不像HTTP那样有Content-Type字段去描述,是一个比较底层的协议,就和TCP一样,如果要用来通信通常需要自己来定一个协议。那么subprotocol就可以作为一个标示来让服务端和客户端之间进行协商用。

客户端在进行连接的时候可以声明自己能接受的子协议类型。这和HTTP请求头里带的Accept和Accept-Encoding头字段一样,说明自己你可以接受那些类型文件,或者编码,通常是压缩类型

<code class="language-text">Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
</code>
Copy after login
Related labels:
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!