资源简介
1.基于kcp协议,实现UDP消息客户端。2.基于kcp协议,实现UDP消息服务器。
代码片段和文件信息
//=====================================================================
//
// KCP - A Better ARQ Protocol Implementation
// skywind3000 (at) gmail.com 2010-2011
//
// Features:
// + Average RTT reduce 30% - 40% vs traditional ARQ like tcp.
// + Maximum RTT reduce three times vs tcp.
// + Lightweight distributed as a single source file.
//
//=====================================================================
#include “ikcp.h“
#include
#include
#include
#include
#include
#include “log.h“
//=====================================================================
// KCP BASIC
//=====================================================================
const IUINT32 IKCP_RTO_NDL = 30; // no delay min rto
const IUINT32 IKCP_RTO_MIN = 100; // normal min rto
const IUINT32 IKCP_RTO_DEF = 200;
const IUINT32 IKCP_RTO_MAX = 60000;
const IUINT32 IKCP_CMD_PUSH = 81; // cmd: push data
const IUINT32 IKCP_CMD_ACK = 82; // cmd: ack
const IUINT32 IKCP_CMD_WASK = 83; // cmd: window probe (ask)
const IUINT32 IKCP_CMD_WINS = 84; // cmd: window size (tell)
const IUINT32 IKCP_ASK_SEND = 1; // need to send IKCP_CMD_WASK
const IUINT32 IKCP_ASK_TELL = 2; // need to send IKCP_CMD_WINS
const IUINT32 IKCP_WND_SND = 32;
const IUINT32 IKCP_WND_RCV = 128; // must >= max fragment size
const IUINT32 IKCP_MTU_DEF = 1400;
const IUINT32 IKCP_ACK_FAST = 3;
const IUINT32 IKCP_INTERVAL = 100;
const IUINT32 IKCP_OVERHEAD = 24;
const IUINT32 IKCP_DEADlink = 20;
const IUINT32 IKCP_THRESH_INIT = 2;
const IUINT32 IKCP_THRESH_MIN = 2;
const IUINT32 IKCP_PROBE_INIT = 7000; // 7 secs to probe window size
const IUINT32 IKCP_PROBE_LIMIT = 120000; // up to 120 secs to probe window
//---------------------------------------------------------------------
// encode / decode
//---------------------------------------------------------------------
/* encode 8 bits unsigned int */
static inline char *ikcp_encode8u(char *p unsigned char c)
{
*(unsigned char*)p++ = c;
return p;
}
/* 解码8位unsigned int */
static inline const char *ikcp_decode8u(const char *p unsigned char *c)
{
*c = *(unsigned char*)p++;
return p;
}
/* encode 16 bits unsigned int (lsb) */
static inline char *ikcp_encode16u(char *p unsigned short w)
{
#if IWORDS_BIG_ENDIAN
*(unsigned char*)(p + 0) = (w & 255);
*(unsigned char*)(p + 1) = (w >> 8);
#else
*(unsigned short*)(p) = w;
#endif
p += 2;
return p;
}
/* decode 16 bits unsigned int (lsb) */
static inline const char *ikcp_decode16u(const char *p unsigned short *w)
{
#if IWORDS_BIG_ENDIAN
*w = *(const unsigned char*)(p + 1);
*w = *(const unsigned char*)(p + 0) + (*w << 8);
#else
*w = *(const unsigned short*)p;
#endif
p += 2;
return p;
}
/* encode 32 bits unsigned int (lsb) */
static inline char *ikcp_encode32u(char *p IUINT32 l)
{
#if IWORDS_BIG_ENDIAN
*(unsigned char*)(p + 0) = (unsigned char)((l >> 0
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 56832 2018-10-22 15:43 kcp-server\Debug\kcp-server.exe
文件 315204 2018-10-22 15:43 kcp-server\Debug\kcp-server.ilk
文件 897024 2018-10-22 15:43 kcp-server\Debug\kcp-server.pdb
文件 3342336 2018-10-16 11:24 kcp-server\ipch\kcp-server-71bd5026\kcp-server-1a34a1ee.ipch
文件 58809 2018-10-16 15:28 kcp-server\kcp-server\Debug\ikcp.obj
文件 1527 2018-10-22 15:43 kcp-server\kcp-server\Debug\kcp-server.log
文件 44053 2018-10-22 15:43 kcp-server\kcp-server\Debug\kcp-server.obj
文件 1835008 2018-10-16 11:24 kcp-server\kcp-server\Debug\kcp-server.pch
文件 3094 2018-10-22 15:43 kcp-server\kcp-server\Debug\kcp-server.tlog\cl.command.1.tlog
文件 39020 2018-10-22 15:43 kcp-server\kcp-server\Debug\kcp-server.tlog\CL.read.1.tlog
文件 2912 2018-10-22 15:43 kcp-server\kcp-server\Debug\kcp-server.tlog\CL.write.1.tlog
文件 175 2018-10-22 15:43 kcp-server\kcp-server\Debug\kcp-server.tlog\kcp-server.lastbuildstate
文件 1742 2018-10-22 15:43 kcp-server\kcp-server\Debug\kcp-server.tlog\li
文件 3278 2018-10-22 15:43 kcp-server\kcp-server\Debug\kcp-server.tlog\li
文件 948 2018-10-22 15:43 kcp-server\kcp-server\Debug\kcp-server.tlog\li
文件 45563 2018-10-16 11:24 kcp-server\kcp-server\Debug\log.obj
文件 10831 2018-10-16 11:24 kcp-server\kcp-server\Debug\stdafx.obj
文件 707584 2018-10-22 15:43 kcp-server\kcp-server\Debug\vc120.idb
文件 249856 2018-10-22 15:43 kcp-server\kcp-server\Debug\vc120.pdb
文件 33834 2018-10-16 15:28 kcp-server\kcp-server\ikcp.c
文件 12328 2018-10-16 09:39 kcp-server\kcp-server\ikcp.h
文件 4165 2018-10-22 15:43 kcp-server\kcp-server\kcp-server.cpp
文件 4837 2018-10-16 11:24 kcp-server\kcp-server\kcp-server.vcxproj
文件 1661 2018-10-16 11:23 kcp-server\kcp-server\kcp-server.vcxproj.filters
文件 4714 2018-09-27 14:03 kcp-server\kcp-server\log.cpp
文件 1905 2017-07-27 23:23 kcp-server\kcp-server\log.h
文件 1531 2018-10-16 11:22 kcp-server\kcp-server\ReadMe.txt
文件 216 2018-10-16 11:22 kcp-server\kcp-server\stdafx.cpp
文件 234 2018-10-16 11:22 kcp-server\kcp-server\stdafx.h
文件 236 2018-10-16 11:22 kcp-server\kcp-server\targetver.h
............此处省略51个文件信息
- 上一篇:2018数模论文LaTex模板V2.0分解版
- 下一篇:水利计算程序
评论
共有 条评论