Skip to content

Commit

Permalink
upload 5th
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkedDestiny committed Nov 5, 2014
1 parent 608c5e1 commit 0c83f1f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions 05.Swoole的自定义协议功能的使用.md
Expand Up @@ -2,10 +2,10 @@
---
#Table of Contents

- [1.为什么要提供自定义协议]()
- [2.EOF标记型协议]()
- [3.固定包头类型协议]()
- [4.特别篇:Http协议-Swoole内置的http_server]()
- [1.为什么要提供自定义协议](#1%E4%B8%BA%E4%BB%80%E4%B9%88%E8%A6%81%E6%8F%90%E4%BE%9B%E8%87%AA%E5%AE%9A%E4%B9%89%E5%8D%8F%E8%AE%AE)
- [2.EOF标记型协议](#2eof%E6%A0%87%E8%AE%B0%E5%9E%8B%E5%8D%8F%E8%AE%AE)
- [3.固定包头类型协议](#3%E5%9B%BA%E5%AE%9A%E5%8C%85%E5%A4%B4%E7%B1%BB%E5%9E%8B%E5%8D%8F%E8%AE%AE)
- [4.特别篇:Http协议-Swoole内置的http_server](#4%E7%89%B9%E5%88%AB%E7%AF%87http%E5%8D%8F%E8%AE%AE-swoole%E5%86%85%E7%BD%AE%E7%9A%84http_server)

---

Expand Down Expand Up @@ -68,7 +68,7 @@ public function onReceive( swoole_server $serv, $fd, $from_id, $data ) {



###**2.固定包头类型协议**
###**3.固定包头类型协议**
固定包头协议是在实际应用中最常用的协议。该协议的内容是规定一个固定长度的包头,在包头的固定位置有一个指定好的字段存放了后续数据的实际长度。这样,服务器端可以先读取固定长度的数据,从中提取出长度,然后再读取指定长度的数据,即可获取一段完整的数据。<br>
在Swoole中,同样提供了固定包头的协议格式。需要注意的是,Swoole只允许二进制形式的包头,因此,需要使用pack、unpack来打包、解包。<br>
通过设置[open_length_check](https://github.com/LinkedDestiny/swoole-doc/blob/master/doc/01.swoole_server%E9%85%8D%E7%BD%AE%E9%80%89%E9%A1%B9.md#15open_length_check)选项,即可打开固定包头协议解析功能。此外还有[package_length_offset](https://github.com/LinkedDestiny/swoole-doc/blob/master/doc/01.swoole_server%E9%85%8D%E7%BD%AE%E9%80%89%E9%A1%B9.md#16package_length_offset),[package_body_offset](https://github.com/LinkedDestiny/swoole-doc/blob/master/doc/01.swoole_server%E9%85%8D%E7%BD%AE%E9%80%89%E9%A1%B9.md#17package_body_offset)和[package_length_type](https://github.com/LinkedDestiny/swoole-doc/blob/master/doc/01.swoole_server%E9%85%8D%E7%BD%AE%E9%80%89%E9%A1%B9.md#18package_length_type)三个配置项用于控制解析功能。[package_length_offset](https://github.com/LinkedDestiny/swoole-doc/blob/master/doc/01.swoole_server%E9%85%8D%E7%BD%AE%E9%80%89%E9%A1%B9.md#16package_length_offset)规定了包头中第几个字节开始是长度字段,[package_body_offset](https://github.com/LinkedDestiny/swoole-doc/blob/master/doc/01.swoole_server%E9%85%8D%E7%BD%AE%E9%80%89%E9%A1%B9.md#17package_body_offset)规定了包头的长度,[package_length_type](https://github.com/LinkedDestiny/swoole-doc/blob/master/doc/01.swoole_server%E9%85%8D%E7%BD%AE%E9%80%89%E9%A1%B9.md#18package_length_type)规定了长度字段的类型。<br>
Expand Down

0 comments on commit 0c83f1f

Please sign in to comment.