Reliable UDP & UDT - XianWorld/xxxgame GitHub Wiki
Technology
-
Streaming Text Oriented Messaging Protocol: Simple (or Streaming) Text Oriented Message Protocol (STOMP), formerly known as TTMP, is a simple text-based protocol, designed for working with message-oriented middleware. It provides an interoperable wire format that allows STOMP clients to talk with any message broker supporting the protocol. It is thus language-agnostic, meaning a broker developed for one programming language or platform can receive communications from client software developed in another language.
-
Real Time Streaming Protocol: The Real Time Streaming Protocol (RTSP) is a network control protocol designed for use in entertainment and communications systems to control streaming media servers. The protocol is used for establishing and controlling media sessions between end points. Clients of media servers issue VCR-style commands, such as play and pause, to facilitate real-time control of playback of media files from the server.
Designs
- 通讯基于udp
Reliable_udp建立在udp协议之上,使用udp来收发数据。
UDP协议的全称是用户数据包协议,在网络中它与TCP协议一样用于处理数据包,是一种无连接的协议。在OSI模型中,在第四层——传输层,处于IP协议的上一层。 UDP有不提供数据包分组、组装和不能对数据包进行排序的缺点,也就是说,当报文发送之后,是无法得知其是否安全完整到达的。与所熟知的TCP(传输控制协议)协议一样,UDP协议直接位于IP(网际协议)协议的顶层。根据OSI(开放系统互连)参考模型,UDP和TCP都属于传输层协议。
- 采用滑动窗口机制防止拥堵
Reliable_udp借鉴tcp协议中的滑动窗口机制来防止网络拥堵,发送方一次只能最多发送对方窗口中的数据,根据通信的进行,窗口不断向后移动。
- 采用ack方式保证消息可靠
Reliable_udp双方连接时相互交换各自起始报文序号,协商mtu值,交换滑动窗口大小。报文到达确认(ACK),是对接收到的数据的最高序列号的确认,并向发送端返回一个下次接收时期望的数据包的序列号(Ack Number)。例如,主机A发送的当前数据报文序号是400,则接收端收到后会返回一个确认号是401的确认号给主机A。 Reliable_udp提供的确认机制,可以在通信过程中可以不对每一个数据包发出单独的确认包(Delayed ACK机制),而是一定间隔,或者对方请求确认(例如发现对方重发了某一报文)时发送。
Reliable_udp也可提供单包确认机制,这样可以减小网络延时。但会带来网络带宽的使用量增大。大容量传输时效率降低。
- 采用mtu分片减少重发几率
Mtu是ip层的一个概念,由于物理链路限制存在一个mtu值,即最大报文长度,一般以太网为1500。如果udp传输的报文大于mtu值,到达ip层时,ip层就会分包然后分包发送,最终在对方主机完成封装成udp报文。如果其中一个分组丢失,则整个报文丢失。为了减少重发的数据量,reliable_udp在发送udp报文时,总是小于设定的mtu值。
- 采用心跳和超时机制保证链接
Reliable_udp内部存在许多定时器来维护双方连接。如下:
-
发送超时时定时器:自发送最后一个报文时t时间段内没有确认回复触发
-
空闲状态定时器,在空闲t时间段内没有数据发送,触发,并发送带确认信息的数据给对方。
-
连接超时定时器,连接时超时触发。
Implements
.NET implementation of Reliable Udp Protocol
Reliable UDP Protocol can be used with Unity3D
A reliable UDP Javascript implementation for node.js