//
|
// 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 */
|