資源簡介
帶gcc工具的linux平臺編譯。

代碼片段和文件信息
/**
?@file ??client.c
?@author??haohaibo
?@date? ??2017/7/11
?@brief???員工管理系統(tǒng)
??運行時要加入對于server端的ip地址和端口號,例如./client?127.0.0.1?9999
?*/
?
#include?“freamwork.h“
static?int?status=0; //運行狀態(tài)
static?char?user[N_SIZE]={0};?//當前用戶名
static?int??current_no?=?0;?//當前用戶ID
?int?main(int?argcconst?char?*argv[])
?{
int?sockfd?=?-1;
int?cho_num?=?0;
MSG?*msg?=?NULL;
msg?=?(MSG*)malloc(sizeof(MSG));
struct?sockaddr_in?serveraddr;
socklen_t?addrlen?=?sizeof(struct?sockaddr);
char?buf[M_SIZE]?=?{0};
status=RUN_1;
#if?1
if(argc?3)
{
printf(“argument?is?too?few\n“);
exit(1);
}
//第一步:創(chuàng)建一個套接字
if((sockfd?=?socket(AF_INET?SOCK_STREAM?0))?0)
{
errlog(“fail?to?socket“);
}
//第二步:填充服務器網(wǎng)絡信息結(jié)構(gòu)體
//inet_addr:將點分十進制IP地址轉(zhuǎn)化為網(wǎng)絡識別的
//htons:將主機字節(jié)序轉(zhuǎn)化為網(wǎng)絡字節(jié)序
//atoi:將數(shù)字型字符串轉(zhuǎn)化為整型數(shù)據(jù)
serveraddr.sin_family?=?AF_INET;
serveraddr.sin_addr.s_addr?=?inet_addr(argv[1]);
serveraddr.sin_port?=?htons(atoi(argv[2]));
//第三步:發(fā)送客戶端的連接請求
if(connect(sockfd?(struct?sockaddr?*)&serveraddr?addrlen)?0)
{
errlog(“fail?to?connect“);
}
//setsockopt(sockfdIPROTO_TCPTCP_NODELAY&enablesizeof(enable));
#endif
#if?1
while(1)
{
while((status==RUN_1))
{
//REMLINE;
fflush(stdin);
??/******************************/
my_printf(“1.login??2.quit?“);
printf(“input?your?choice:?“);
scanf(“%d“&cho_num);
REMLINE;
switch(cho_num)
{
case?1:
do_login(sockfdmsg);break;
case?2:
do_quit(sockfdmsg);break;
default:
puts(“input?errorplease?try?again“);
break;
}
}
while((status==RUN_2))
{
//REMLINE;
fflush(stdin); ??/******************************/
my_printf(“1.add????2.delete????3.modify 4.select? 5.quit“);
printf(“input?your?choice:“);
scanf(“%d“&cho_num);
REMLINE;
switch(cho_num)
{
case?1:
do_add(sockfdmsg);break;
case?2:
do_delect(sockfdmsg);break;
case?3:
do_modify(sockfdmsg);break;
case?4:
do_select(sockfdmsg);break;
case?5:
do_quit(sockfdmsg);break;
default:
puts(“input?errorplease?try?again:“);
break;
}
}
while((status==RUN_3))
{
//REMLINE;
fflush(stdin); ??/******************************/
my_printf(“1.modify ??2.select? 3.quit“);
printf(“input?your?choice:“);
scanf(“%d“&cho_num);
REMLINE;
switch(cho_num)
{
case?1:
do_modify(sockfdmsg);break;
case?2:
do_select(sockfdmsg);break;
case?3:
do_quit(sockfdmsg);break;
default:
puts(“input?errorplease?try?again:“);
break;
}
}
}
close(sockfd);
return?0;
?}
?#endif
?void?my_printf(const?char?*str)
?{
puts(“******************************“);
puts(str);
puts(“******************************“);
?}
/**申請登錄*/
int?do_login(int?sockfdMSG?*msg)
{
//msg=(MSG?*)malloc(M_SIZE);
char?name[N_SIZE];
char?passwd[N_SIZE];
printf(“please?input?name:?“);
scanf(
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????7269??2017-07-12?11:46??test\1\a.out
?????文件???????8389??2017-07-12?18:51??test\1\client.c
?????文件???????2293??2017-07-12?11:33??test\1\freamwork.h
?????文件????????114??2017-07-12?10:14??test\1\Makefile
?????文件???????9702??2017-07-12?11:55??test\1\server.c
?????目錄??????????0??2017-07-12?20:13??test\1
?????目錄??????????0??2017-07-12?13:10??test
-----------?---------??----------?-----??----
????????????????27767????????????????????7
- 上一篇:色彩改進型Retinex彩色圖像增強方法
- 下一篇:U盤克隆工具
評論
共有 條評論