先附上git地址
https://github.com/huqiang0204/huqiang.UnitySubThreadUI
这里kcp设计是在UDP和Envelope的基础只是扩展出来的,具有很好的稳定性和速度,还有内网穿透,服务器可部署在内网供外网访问,详情请去看我git上的ip重定向示例。
Envelope中设计了消息分卷和分卷id,当双端通信时,接受的消息时会将消息id回传,通知对方消息已经接受,否则消息超时时则重新发送,消息超时时间,和连接超时时间可以自定义
代码请看/Core/Communication下的KcpLink和KcpEnvelope
连接超时时间在KcpLink中
public static long TimeOut = 50000000;//5*1000*10000断开连接默认超时为5秒
public void Send(byte[] data, byte type)//发送数据,和数据类型,数据类型可自定义
public virtual void Dispatch(byte[] dat, byte tag)//派发接受到的数据,数据是已经通过封包解包过的
数据超时时间定义在KcpEnvelope中
public byte[][] GetFailedData(long now, long timeout = 5000000)//失败的消息,这里默认给的500毫秒
ip重定向后面再介绍