-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
54 lines (45 loc) · 996 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "kcp.h"
DWORD StringToHash(char* lpszBuffer)
{
DWORD dwHash = 0;
while (*lpszBuffer)
{
dwHash = ((dwHash << 25) | (dwHash >> 7));
dwHash = dwHash + *lpszBuffer;
lpszBuffer++;
}
return dwHash;
}
int main()
{
//CHAR str[] = "OutputDebugStringA";
//DWORD hash = StringToHash(str);
//printf("0x%X", hash);
kcp m_kcp;
char temp[] = "hello";
char sendbuf[1024] = { 0 };
char recvbuf[1024] = { 0 };
m_kcp.start("10.2.0.28", 9999);
long current;
long slap = clock() + 1000;
int index = 0;
while (clock() < 60 * CLOCKS_PER_SEC)
{
Sleep(100);
//m_kcp.update();
current = clock();
for (; current >= slap; slap += 2000)
{
sprintf(sendbuf, "%s %d", temp, index++);
m_kcp.send(sendbuf, strlen(sendbuf));
printf("[Send]:%s\n", sendbuf);
}
while (1) {
int res = m_kcp.recv(recvbuf, sizeof(recvbuf));
if (res < 0) break;
printf("[Recv]:%s\n", recvbuf);
}
}
m_kcp.end();
return 0;
}