-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientGroup.cpp
More file actions
executable file
·132 lines (116 loc) · 2.87 KB
/
Copy pathClientGroup.cpp
File metadata and controls
executable file
·132 lines (116 loc) · 2.87 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// ClientGroup.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <time.h>
#include <WinSock2.h>
#include <MSWSock.h>
#include <Windows.h>
#include <process.h>
unsigned __stdcall ThreadProc(LPVOID lParam);
unsigned __stdcall ThreadSend(LPVOID lParam);
#define MAX_THREAD 10
HANDLE hThread[MAX_THREAD] = {0};
int flag = 0;
SOCKET sockc[2048] = {0};
SOCKET sockc1[1024] = {0};
struct sock
{
int a;
int b;
long port;
};
int main(int argc, char* argv[])
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 1, 1 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
return 0;
}
if ( LOBYTE( wsaData.wVersion ) != 1 ||
HIBYTE( wsaData.wVersion ) != 1 ) {
WSACleanup();
return 0;
}
int i;
int a = 0, b= 0;
int para = 512;
hThread[0] = (HANDLE)_beginthreadex(NULL, 0, (unsigned (__stdcall *) (void *))ThreadProc,(void *)para, 0, NULL);
// hThread[1] = (HANDLE)_beginthreadex(NULL, 0, (unsigned (__stdcall *) (void *))ThreadProc,(void *)para, 0, NULL);
hThread[9] = (HANDLE)_beginthreadex(NULL, 0, (unsigned (__stdcall *) (void *))ThreadSend,(void *)sockc,0,NULL);
///hThread[2] = (HANDLE)_beginthreadex(NULL, 0, (unsigned (__stdcall *) (void *))ThreadProc,(void *)co, 0, NULL);
SOCKADDR_IN addrSrv;
for (i = 0; i<200; i++)
{
sockc[i] = socket(AF_INET, SOCK_STREAM, 0);
addrSrv.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
addrSrv.sin_family = AF_INET;
int port = 5053;
int count = 200;
if (i > count)
{
count = count +200;
port = port+1;
}
addrSrv.sin_port = htons(port);
int ret = connect(sockc[i], (SOCKADDR*)&addrSrv, sizeof(SOCKADDR));
//select()
//Sleep(1000);
if(ret == -1)
{
a++;
printf("连接失败= %d , 失败总数:%d\n", i, a);
}
else
{
b++;
printf("连接成功= %d ,成功总数:%d\n", i, b);
}
}
Sleep(10000);
for (i = 0; i<1024; i++)
{
closesocket(sockc[i]);
}
Sleep(10);
//socket()
printf("Hello World!\n");
return 0;
}
unsigned __stdcall ThreadProc(LPVOID lParam)
{
int* cout = (int*)lParam;
//SOCKET sock[10];
for (int i = 200; i < *cout; i++)
{
sockc1[i] = socket(AF_INET, SOCK_STREAM, 0);
SOCKADDR_IN addrSrv;
addrSrv.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
addrSrv.sin_family = AF_INET;
addrSrv.sin_port = htons(5050);
if (connect(sockc1[i], (SOCKADDR *) &addrSrv, sizeof(SOCKADDR)))
{
printf("failed socket %d \n", i+1);
}
send(sockc1[i], "12 12", 10, 0);
}
return 0;
}
unsigned __stdcall ThreadSend(LPVOID lParam)
{
// SOCKET* psock = (SOCKET*) lParam;
while (1)
{
for (int i= 0; i < 1024; i++)
{
if (sockc != 0)
{
send(sockc[i], "111111111", 256, 0);
}
}
Sleep(1000);
}
return 0;
}