-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtclient.c
76 lines (47 loc) · 1.29 KB
/
tclient.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#define PORT 4444
void * dosome(void * s){
int clientSocket, ret;
struct sockaddr_in serverAddr;
char buffer[100];
clientSocket = socket(AF_INET, SOCK_STREAM, 0);
if(clientSocket < 0) perror("error in socket\n");
memset(&serverAddr, '\0', sizeof(serverAddr));
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(PORT);
serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
ret = connect(clientSocket, (struct sockaddr*)&serverAddr, sizeof(serverAddr));
if(ret < 0) perror("error in connect\n");
int k=0;
while(k++ < 20){
long long x=k;
bzero(buffer, 100);
sprintf(buffer, "%lld", x);
send(clientSocket, &buffer, sizeof(buffer), 0);
bzero(buffer, 100);
if(recv(clientSocket, &buffer, sizeof(buffer), 0) < 0){
printf("[-]Error in receiving data.\n");
}else{
printf("Server: \t%s\n", buffer);
}
}
return NULL;
}
int main(){
pthread_t thrd[10];
for (int i = 0 ; i<10 ; i++){
pthread_create(&thrd[i], NULL, dosome, NULL);
}
for(int i = 0; i<10 ; i++){
pthread_join(thrd[i], NULL);
}
return 0;
}