-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.c
140 lines (118 loc) · 2.54 KB
/
client.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
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
133
134
135
136
137
138
139
140
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>
#include<unistd.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
int connect_sock()
{
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
assert(sockfd != -1);
struct sockaddr_in saddr;
memset(&saddr, 0, sizeof(saddr));
saddr.sin_family = AF_INET;
saddr.sin_port = htons(6000);
saddr.sin_addr.s_addr = inet_addr("127.0.0.1");
int res = connect(sockfd, (struct sockaddr*)&saddr, sizeof(saddr));
assert(res != -1);
return sockfd;
}
int face()
{
printf("\t智能停车场\n");
printf("1.登录\n");
printf("2.注册\n");
printf("3.找回密码\n");
printf("0.退出\n");
printf("请输入你的选择(数字):");
int choose = -1;
scanf("%d",&choose);
return choose;
}
void Login(int sockfd)
{
system("clear");
printf("\n\t欢迎进入登录界面\n\n");
printf("输入手机号:");
char phoneNum[12] = { 0 };
scanf("%s",phoneNum);
strcat(phoneNum,"|");
printf("输入密码:");
char password[50] = {0};
scanf("%s",password);
char str[128] = { 0 };
sprintf(str,"1|%.12s%.50s",phoneNum,password);
puts(str);
send(sockfd,str,strlen(str),0);
memset(str,0,sizeof(str));
recv(sockfd,str,127,0);
if(strcmp(str,"true") == 0)
{
printf("Login true\n");
}
else
{
printf("Login false\n");
}
}
void Registration(int sockfd)
{
char sex[10] = { 0 };
char memberName[20] = { 0 };
char phone[12] = { 0 };
char birthday[11] = { 0 };
char password[5] = { 0 };
system("clear");
printf("\n\t欢迎进入注册界面\n\n");
printf("会员名字:");
scanf("%s",memberName);
puts(memberName);
printf("性别:(man or woman)");
scanf("%s",sex);
puts(sex);
printf("手机号:");
scanf("%s",phone);
printf("请输入出生年月日:(2000-1-1)");
scanf("%s",birthday);
printf("请输入密码:(至多49位)");
scanf("%s",password);
char str[128] = { 0 };
sprintf(str,"2|%.20s|%.10s|%.11s|%.11s|%.5s",memberName,sex,phone,birthday,password);
puts(str);
send(sockfd,str,strlen(str),0);
memset(str,0,sizeof(str));
recv(sockfd,str,127,0);
if(strcmp(str,"true") == 0)
{
printf("Register true\n");
}
else
{
printf("Register false\n");
}
}
int main()
{
int sockfd = connect_sock();
while(1)
{
int choose = face();
switch(choose)
{
case 0:
break;
case 1:
Login(sockfd);
break;
case 2:
Registration(sockfd);
break;
case 3:
break;
}
}
close(sockfd);
exit(0);
}