🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[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 应用协议总结 应用协议负责数据包数据的格式解析。