RTMP Handshake(握手协议)

RTMP流播放的流程首先要进行握手操作,才能进行后续的connect和createStream等操作, 本文简单阐述握手基础知识.

Handshake Diagram

RTMP Handshake(握手协议)_第1张图片
**Handshake Diagram in Adobe’s Real Time Messaging Protocol**

wireshark分析握手基本流程

用wireshark对rtmp的包进行抓包分析:


RTMP Handshake(握手协议)_第2张图片
rtmp点播流程

可以看到前三个报文是握手协议:

握手协议

从以上可看出握手的实际流程为三个步骤:

  1. Client -> Server
    C0+C1
  2. Server -> Client
    S0+S1+S2
  3. Client -> Server
    C2
    可以看出握手的起点是Client(RMTP播放器)发送C0+C1, 结束是Server收到Client的C2.
    其中C0 C1 C2 S0 S1 S2的大小都是固定的.
    C2 S2属于用于确认(Ack)的包
Step 1: C0 + C1

C0 + C1一起发送.
其中C0一个字节, 固定为03.
C11536个字节.
数据包总长度为:
1 + 1536 = 1537

In C0, this field identifies the RTMP version requested by the client.
In S0, this field identifies the RTMP version selected by the server.
The version defined by this specification is 3.
0-2 are deprecated values used by earlier proprietary products;
4-31 are reserved for future implementations;
32-255 are not allowed (to allow distinguishing RTMP from text-based protocols, which always start with a printable character).

RTMP Handshake(握手协议)_第3张图片
C0
RTMP Handshake(握手协议)_第4张图片
C1
Step 2: S0+S1+S2

S0+S1+S2一起发送.
S0为1个字节,固定为03.
S1S2都为1536个字节.
整个数据包总长度为:
1 + 1536 + 1536 = 3073

RTMP Handshake(握手协议)_第5张图片
S0
RTMP Handshake(握手协议)_第6张图片
S1
RTMP Handshake(握手协议)_第7张图片
S2
Step 3: C2

C2为1536个字节.
RTMP Server接收到C2意味着握手成功结束.

RTMP Handshake(握手协议)_第8张图片
C2

References:

rtmp_specification_1.0.pdf

你可能感兴趣的:(RTMP Handshake(握手协议))