1、客户端1.7版本 多线程分组模拟高频发送数据
如上图所示的多线程客户端结构,启动多个线程对客户端进行socket创建->连接->发送的业务;
//客户端socket连接数量
const int cCount = 1000;
const int tCount = 4; //线程数量
//客户端socket数组
EasyTcpClient* client[cCount];
mutex m_lock;
void sendThread(int theadId)
{
int count = cCount / tCount;
int begin = (theadId-1) * count; //计算每个线程需要处理的socket数量
int end = theadId * count;
char* ipAdd = new char[100];
for (int i = begin; i < end; i++)
{
client[i] = new EasyTcpClient();
}
ipAdd = "127.0.0.1";
unsigned port = 4567;
for (int i = begin; i < end; i++)
{
client[i]->ConnectServer(ipAdd, port);
m_lock.lock();
cout << "Connect:" << i << endl;