protocols php,另:Protocols网络协议

[TOC]

* * * * *

## 1 网络协议文件

~~~

Workerman\Protocols\

ProtocolInterface.php ;协议接口

Frame.php ;frame应用层协议

Http.php ;http应用层协议

Text.php ;text应用层协议

Websocket.php ;websocket应用层协议

Ws.php ;websocket客户端协议

~~~

## 2 网络协议接口(ProtocolInterface.php)

>[info] 成员方法

### input():检查数据包完整性

~~~

public static function input($recv_buffer, ConnectionInterface $connection);

~~~

### decode():解码数据包数据回调onMessage

~~~

public static function decode($recv_buffer, ConnectionInterface $connection);

~~~

### encode():编码数据包协议等待发送

~~~

public static function encode($data, ConnectionInterface $connection);

~~~

## 3 frame应用层协议(Frame.php)

>[info] 成员方法

### input():Frame数据格式检查完整性

~~~

public static function input($buffer, TcpConnection $connection)

~~~

### decode($buffer):Frame数据包解码

~~~

public static function decode($buffer)

~~~

### encode($buffer):Frame数据包编码

~~~

public static function encode($buffer)

~~~

## 4 http应用层协议(Http.php)

>[info] 成员方法

### input():Http数据包格式检查完整性

~~~

public static function input($recv_buffer, TcpConnection $connection)

~~~

### decode():Http数据包解码

~~~

public static function decode($recv_buffer, TcpConnection $connection)

~~~

### encode():Http数据包编码

~~~

public static function encode($content, TcpConnection $connection)

~~~

## 5 text应用层协议(Text.php)

>[info] 成员方法

### input():Text数据包格式检查完整性

public static function input($buffer, TcpConnection $connection)

### encode():encode数据包编码

public static function encode($buffer)

### decode():decode数据包解码

public static function decode($buffer)

## 6 Websocket应用层协议(Websocket.php)

>[info] 成员方法

### input():Text数据包格式检查完整性

~~~

public static function input($buffer, ConnectionInterface $connection)

~~~

### encode():encode数据包编码

~~~

public static function encode($buffer, ConnectionInterface $connection)

~~~

### decode():decode数据包解码

~~~

public static function decode($buffer, ConnectionInterface $connection)

~~~

### dealHandshake()握手处理

~~~

protected static function dealHandshake($buffer, $connection)

~~~

### parseHttpHeader()解析http头

~~~

protected static function parseHttpHeader($buffer)

~~~

## 7 Ws客户端协议(Ws.php)

>[info] 成员变量

~~~

;协议最小头部

const MIN_HEAD_LEN = 2;

;blob格式

const BINARY_TYPE_BLOB = "\x81";

;array格式

const BINARY_TYPE_ARRAYBUFFER = "\x82";

~~~

>[info] 成员方法

### input() 数据包完整性检查

~~~

public static function input($buffer, $connection)

~~~

### encode() 数据包编码

~~~

public static function encode($payload, $connection)

~~~

### decode() 数据包解码

~~~

public static function decode($bytes, $connection)

~~~

### sendHandshake()发送握手协议

~~~

public static function sendHandshake($connection)

~~~

### dealHandshake()处理握手协议

~~~

public static function dealHandshake($buffer, $connection)

~~~

## 8 应用协议总结

应用协议负责数据包数据的格式解析。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值