-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_ssl_.c
105 lines (101 loc) · 2.19 KB
/
client_ssl_.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
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
#include<sys/types.h>
#include<sys/socket.h>
#include<stdio.h>
#include<errno.h>
#include<stdlib.h>
#include<arpa/inet.h>
#include<string.h>
#include<unistd.h>
#include<pthread.h>
#define pace_size 1024
/*#define check(a,b) if(a==-1)\
{\
perror(b);\
return -1;\
}
*/
#include"socket.h"
char cc=0;
int sends(struct sock_space * arg)
{
int i;
while(0==cc && 0!= strcmp("quit\n", arg->space))
{
// fgets(
fgets(arg->space, pace_size, stdin);
i=send(arg->sockfd, arg->space, strlen(arg->space)+1, 0);
check(i,"send")
}
cc=1;
close(arg->sockfd);
printf("send channel close\n");
}
// ./clent server_ip server_port
int main(int N, char * COMMAND[])
{
if(3 !=N)
{
printf(" %s server_ip server_port \n",COMMAND[0]);
return 0;
}
int c=socket(AF_INET, SOCK_STREAM, 0);
check(c,"socket:")
struct sockaddr_in hi;
hi.sin_family=AF_INET;
hi.sin_port=htons(atoi(COMMAND[2]));
hi.sin_addr.s_addr=inet_addr(COMMAND[1]);
memset(hi.sin_zero, 0, sizeof hi.sin_zero);
int i=0;
i=connect(c,(struct sockaddr *)&hi, sizeof hi);
check(i,"connect:")
char recv_space[pace_size], send_space[pace_size];
struct sock_space sds;
sds.sockfd=c;
sds.space=send_space;
sds.len=sizeof send_space;
long int tid;
pthread_create(&tid,NULL,(void *(*)(void *)) sends, &sds);
//int i=fork();
//char cc=0;
//i=fork();
//if(!i)
//{
//while(0 != strcmp("quit", recv_space))
//printf("I try to accept:\n");
while(0==cc &&0 != strcmp("quit\n", recv_space))
{
i=recv(c, recv_space, pace_size, 0);
//i=recv(c, recv_space, pace_size, MSG_PEEK);
//if(0== i)
// break;
check(i,"recv")
//puts(recv_space);
//printf("i=%d\n",i);
//printf("client: %s",recv_space);
//puts(recv_space);
printf("%s",recv_space);
}
//cc=1;
//printf("I finished T _ T \n");
if (0==c)
close(c);
printf("client socket closed\n");
return 0;
/* }
else
{
while(0==cc &&0!=strcmp("quit\n", send_space))
{
fgets(send_space, pace_size, stdin);
//int d=strlen(send_space)+1;
//send(c, send_space, strlen(send_space)+1, 0);
//i=send(c, send_space, d, 0);
i=send(c, send_space, strlen(send_space)+1, 0);
check(i,"send")
//printf("Send %d bytes\n",d);
}
cc=1;
}
return 0;
*/
}