-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
62 lines (49 loc) · 1.02 KB
/
main.cpp
File metadata and controls
62 lines (49 loc) · 1.02 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
#include <stdio.h>
#include <winsock2.h>
#define DST_IP "192.168.1.99"
#define DST_PORT 10000
void init()
{
WSADATA wsd;
if (WSAStartup(MAKEWORD(2,2), &wsd) != 0)
{
printf("Failed to load Winsock!\n");
}
}
int my_connect()
{
SOCKET sock;
struct sockaddr_in addrServer;
sock = socket(AF_INET,SOCK_STREAM,0);
if(sock == INVALID_SOCKET)
{
printf("socket Error[%d]\n",GetLastError());
return -1;
}
addrServer.sin_family = AF_INET;
addrServer.sin_addr.s_addr = inet_addr(DST_IP);
addrServer.sin_port = htons(DST_PORT);
if(connect(sock,(const struct sockaddr *)&addrServer,sizeof(sockaddr)) != 0)
{
return -2;
}
return 0;
}
int main()
{
unsigned int i;
int err;
init();
for(i = 0; i < 130; ++i){
err = my_connect();
if(err == 0){
printf("[%d]connect [%s:%d] sucess\n", i, DST_IP, DST_PORT);
}else
{
printf("[%d]connect [%s:%d] failed[%d]\n", i, DST_IP, DST_PORT, GetLastError());
}
Sleep(100);
}
scanf("%d", &err);
return 0;
}