单军华
2017-07-12 20d1260d26b028897f3c0935c12fc35aa37b2e93
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
//  client_test.h
//  GoldRich
//
//  Created by WindShan on 2017/3/8.
//  Copyright © 2017年 WindShan. All rights reserved.
//
 
#ifndef client_test_h
#define client_test_h
 
#include "NetStream.h"
#include "IClientSocket.h"
 
using namespace std;
 
void on_success()
{
    printf("connect success\n");
}
 
void on_connect_err()
{
    printf("connect error\n");
}
 
void on_connect_timeout()
{
    printf("connect time out\n");
}
 
void on_recv_pkg(CNetStream* pkg)
{
    printf("receive a server pkg\n");
    if (pkg)
    {
        const char* str = pkg->readString();
        printf("字符串:%s\n",str);
    }
}
 
int startTest()
{
    std::mutex mem_mutex;
    IClientSocket::InitSockEnv();
    const int BUF_SIZE = 64;
    
    char* p = new char[10*1024*1024];
    memset(p,0,10*1024*1024);
    
    char* p1 = new char[10*1024*1024];
    
    int n = 1000000000;
    while (n >0)
    {
        n--;
    }
    
    clock_t ts = clock();
    
    mem_mutex.lock();
    memcpy(p1,p,10*1024*1024);
    mem_mutex.unlock();
    
    clock_t te = clock();
    printf("need time = %d\n",te - ts);
    
    IClientSocket cl;
    cl.Connect("127.0.0.1",7000,10,on_success,on_connect_timeout,on_connect_err,on_recv_pkg);
    CNetStream st;
    st.writeString("1234565788idfsfs搜狗五笔");
    cl.SendStream(&st);
    
    while (true)
    {
        cl.process();
        CNetStream sss;
        sss.writeString("1234565788idfsfs搜狗五笔");
        cl.SendStream(&sss);
        Sleep(10000);
    }
    
    cl.Close();
    
    IClientSocket::UninitSockEnv();
    return 0;
}
 
#endif/* client_test_h */