嵌入式linux应用程序设计 课程设计多用户网络版学生学藉管理系统说明书_第1页
嵌入式linux应用程序设计 课程设计多用户网络版学生学藉管理系统说明书_第2页
嵌入式linux应用程序设计 课程设计多用户网络版学生学藉管理系统说明书_第3页
嵌入式linux应用程序设计 课程设计多用户网络版学生学藉管理系统说明书_第4页
嵌入式linux应用程序设计 课程设计多用户网络版学生学藉管理系统说明书_第5页
已阅读5页,还剩29页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、多用户网络版学生学藉管理系统 课程设计说明书 课 程 名 称 : 嵌入式 linux 应用程序设计 年级/专业/班 : 2009 级软件工程 1 班 学 生 姓 名 : 学 号 : 09436111、12、13、14、15、16、17 指 导 教 师 : 开 题 时 间 : 2012 年 03 月 14 日 完 成 时 间 : 2012 年 04 月 07 日 目 录 摘摘 要要 .3 一、引言一、引言 .6 二、设计目的与任务二、设计目的与任务 .6 1、本课程设计的目的.6 2、本课程设计的任务.7 三、设计方案三、设计方案 .7 1、需求分析.7 1.1 问题描述.7 1.2 功能要求.

2、7 1.3 问题的解决方案.8 2、概要设计.8 2.1 设计图.8 2.2 数据结构.10 2.3 函数设计.10 3、详细设计.11 4、程序清单.14 服务器主要功能函数.14 四、程序调试与体会四、程序调试与体会 .26 1、程序调试.26 2、体会.27 五、运行结果五、运行结果 .28 六、参考文献六、参考文献 .33 摘摘 要要 嵌入式 linux 是一种嵌入到硬件设备的操作系统,也是一种功能强大的应 用程序开发平台。支持 c 语言开发,既有 c 语言自带的库函数,也有嵌入式 linux 自己的系统 c 库,在目前的嵌入式软件开发行业有着举足轻重的作用。 在嵌入式 linux 应

3、用程序设计中主要有以下特点:网络、多用户、 i/o、socket、进程控制、进程通信和线程等。学好嵌入式 linux 应用程序设计 绝不是纯技术问题,需要综合考虑多方面的因素,加深对网络编程和底层通信 的理解。因此必须强调多上机实践。本课程设计通过 c 实现客户端和服务器之 间的通信,客户端发出请求,服务器实现增、删、改、查等操作,然后返回相 关信息给客户端。 本课程设计通过 socket 实现客户端和服务器之间的通信。服务器生产自己 的 socket 流,把自己的端口绑定出去,然后监听有无客服端的链接。客服端也 生产自己的 socket 流,然后链接服务器,用系统定义好的 struct me

4、ssage 结 构体传输消息,通过 send_msg()和 rev_msg()函数接发消息。如客户端发送注 册消息给服务器,在客户端完成账号和密码的输入,服务器接收到消息后进行 验证,验证无误后写入文件并发送注册成功信息给客户端。 在设计过程中,我们用心的从一个开发项目的程序员的角度出发并解决了 自己在程序中的多处不足和缺陷。例如在录入学生学籍信息时,设计了关于数 据有效性的操作等。在系统的设计中我们加强了界面的美观设计,使程序在简 洁的基础上可读更强,更人性化!最后我们在设计过程中也尝试了创新的方法, 也收到了很好的效果。总之,通过此课程设计,我们都感觉到自己在整体上有 了一个很大的提高,知

5、识更加系统化,理论化,我们会继续努力课不断地专研 关键字:网络、多用户、i/o、socket、进程控制、进程通信、线程。 abstractabstract embedded linux is a kind of embedded hardware equipment to the operating system, is also a powerful application development platform. support c language development, both c language own library function, also have embedded

6、 linux systems c library, in the present embedded software development industry has a pivotal role. in embedded linux applications design basically has the following characteristics: network, many users, i/o, socket, process control, process, communication and thread, etc. learn embedded linux appli

7、cation design is not pure technical problems, takes into account many factors, deepen our understanding of the network programming and the bottom of the communication understanding. so must emphasize more practice. the course is designed to achieve by c client and server of communication between the

8、, the client is requested, increase, delete, server practice, check the function, and then returns to the information related to the client. this course design through the socket realize the client and the server of the communication between. server socket of their production flow, oneself of the po

9、rt binding go out, and then listening for the customer service links. the production of their customer service and socket flow, and then link server, with good struct message system defined structures transmission news, through the send_msg () () function and rev_msg receiver news. if client sends m

10、essages to the server registered at the client complete account and password input, the server receives news verification, verification and written to the file and send information to the client registered success. in the design process, we have the intention of a development project from the point

11、of view of the programmers and solved their in the program the shortage and defects. for example in the student status information input students, about the effectiveness of the design data manipulation, etc. in the design of the system, we strengthened the interface of the beautiful design, makes t

12、he program in concise basis can be read, stronger, more human! finally, we in the design process and try innovative ways, also has received the good effect. all in all, through this course design, we all feel on the whole have a greatly increased, knowledge more systematic and theoretical, we will c

13、ontinue to work hard lessons constantly grinds only key word: network, many users, i/o, socket, process control, process communication, thread. 嵌入式嵌入式 linuxlinux 应用程序设计应用程序设计课程设计课程设计 -多用户网络版学生学藉管理系统多用户网络版学生学藉管理系统 一、引言一、引言 随着人们生活水平的提高,计算机发展异常迅速。如今,计算机已经深入 到我们社会的各个领域,计算机的使用也已不再局限于科学计算,它已进入人 类社会的各个领域并发

14、挥着越来越重要的作用。通过计算机对各类问题求解已 经成为一种高效、快捷的方式。 嵌入式 linux 应用程序设计是一门实践性很强的课程,光靠听课和看书是 学不好的。衡量学习的好坏的标准不是懂不懂。因此必须强调多编程,多上机 实践。所以开设了这次课程设计,目的在于使学生达到熟练掌握嵌入式 linuxc 编程基本知识的技能,掌握其应用程序设计的基本思路和方法,能够利用所学 的基本知识和技能,做一个简单的多用户网络版的管理系统。这对于进一步巩 固嵌入式 linuxc 编程知识是一个很好的机会。 本课程设计采用嵌入式 linuxc 程序设计语言,通过嵌入式 linuxc 实现客 户端和服务器之间的通信

15、,客户端发出请求,服务器实现增、删、改、查等操 作,然后返回相关信息给客户端。 二、设计目的与任务二、设计目的与任务 1、本课程设计的目的 在嵌入式 linux 操作系统环境下,使用 linux c 编程实现了一个功能相对 简单的多用户的字符界面的网络版的学生学藉管理系统。通过对该简单系统的 设计,能够熟悉掌握嵌入式应用程序设计技巧,加深对 i/o、socket、进程控 制、进程间通信和线程等底层编程的理解,编制结构清晰、风格良好、数据结 构适当的 linux c 程序。 2、本课程设计的任务 实现服务端和客户端,服务端为某学校,客户端为教务。服务端完成系统 主要功能模块的实现和数据的存储,客

16、服端完成各种服务请求的操作界面的实 现和数据的输入,操作界面以菜单方式工作。 通过这次课程设计,达到更加灵活的运用所学的理论和知识和方法,以及 独立分析和解决问题的能力;培养实事求是、认真、严谨的科学态度和刻苦钻 研不断创新的精神,逐步建立正确的全局观念。 三、设计方案三、设计方案 1 1、需求分析需求分析 1.11.1 问题描述问题描述 实现服务端和客户端,服务端为某学校,客户端为教务。服务端完成系统 主要功能模块的实现和数据的存储,客服端完成各种服务请求的操作界面的实 现和数据的输入,操作界面以菜单方式工作。 1.21.2 功能要求功能要求 1) 用户管理模块:客户端完成用户注册和申请,服

17、务端完成用户验证。 2) 学藉输入模块:客户端完成学生学藉相关信息的输入(学号,姓名, 性别,年龄,籍贯,系别,专业,班级)。服务端完成对数据的保存, 保存成文件。 3) 显示学藉模块:客户端提出显示请求,服务端发送相关数据到客服端 并显示。 4) 删除学生记录模块:客户端提出记录删除请求(按学号),服务端完成 对相关数据的删除并进行文件的更新。 5) 修改学生学藉记录模块:客户端提出记录修改请求(按学号),服务端 完成对记录修改并进行文件的更新。 6) 学生学藉查询模块:客户端提出学生学藉查询请求(按学号),服务 端完成对图书信息查询并将查询结果返回给客户端。 1.31.3 问题的解决方案问

18、题的解决方案 根据题目要求,可以将问题的解决分为以下步骤: 1) 整体分析,建立功能模块框图及界面的组织和设计。 2) 分析各个模块及他们之间的关系。 3) 根据问题描述,设计模块。 4) 完成模块中各个函数的描述。 5) 完成模块中各个函数的定义。 6) 完成功能应用模块。 7) 功能调试。 8) 完成问题总结报告。 2 2、概要设计、概要设计 2.12.1 设计图设计图 图 3-1 系统模块图 服务器 客户端客户端客户端 图 3-2 使用 tcp 协议 socket 程流程图 图 3-3 学藉管理系统客户端模快图 图 3-4 学藉管理系统服务器模快图 注册信 息输入 登录信 息输入 学藉信

19、 息录入 发送显示信 息请求 发送删除信 息请求 发送修改 信息请求 发送查询 信息请求 学藉管理系统 客户端 退出 注册信 息验证 登录信 息验证 学藉信 息存储 学藉信息读 出 删除信息查 找 查询信息 查找退出 学藉管理系统 服务器 修改信息 查找 2.22.2 数据结构数据结构 本系统中主要的数据结构是用于客户端和服务器发送信息的 struct message、客户通信节点信息 struct _client_inf 和用户节点链表信息 struct _link_node。 /定义 socket 消息数据结构 struct message char flag20;/聊天类型 char n

20、ame20;/用户姓名 char msgmaxlen;/正文 ; /客户通信节点信息 typedef struct _client_inf char name10;/客户姓名 int fd;/客户通信 socket struct sockaddr_in addr;/客户 socket 地址 pthread_t pid;/客户使用线程 pid client_inf,datatype; /用户节点链表信息 typedef struct _link_node datatype data; struct _link_node *next; link_node,*linklist; 2.32.3 函数设

21、计函数设计 函数主要功能描述 客户端: void menu() 登陆成功显示界面 void handle_regist() 提出注册请求 void handle_login() 提出登陆请求 void handle_input() 学藉信息录入 void handle_display() 发送显示信息请求 void handle_delet() 发送删除信息请求 void handle_update() 发送修改信息请求 void handle_select() 发送查询信息请求 void handle_exit() 退出 服务器: void user_manage() 用户管理函数 void

22、 *pthread_accept(void *arg) 等待接收 socket 连接线程处理 void *pthread_handleclient(void *arg)线程处理函数 int reg_check(struct message sock_msg) 核对注册请求 int log_check(struct message sock_msg) 核对登陆请求 计算参数所指定的文件中的记录的个数的函数 int count(char * a) 服务器信息存储 void handle_input(struct message sock_msg,client_inf client_inf) 读出学

23、藉信息 void handle_display(client_inf client_inf) 删除信息查找 void handle_delete(struct message sock_msg,client_inf client_inf) 修改信息查找 void handle_update(struct message sock_msg,client_inf client_inf) 查询信息查找 void handle_select(struct message sock_msg,client_inf client_inf) 3 3、详细设计、详细设计 主要函数功能详细说明: 客户端: voi

24、d handle_regist() /提出注册请求 输入用户名和两次密码; 发送给客户端; send_msg(sockfd,socket_msg); void handle_login() /提出登陆请求 输入用户名和密码; send_msg(sockfd,socket_msg); void handle_input() /学藉信息录入 输入学生学藉相关信息; send_msg(sockfd,socket_msg); void handle_display()/发送显示信息请求 发送显示请求; send_msg(sockfd,socket_msg); void handle_delet()/发

25、送删除信息请求 发送删除请求; send_msg(sockfd,socket_msg); void handle_update()/发送修改信息请求 发送修改请求; send_msg(sockfd,socket_msg); void handle_select()/发送查询信息请求 发送查询请求; send_msg(sockfd,socket_msg); void handle_exit()/退出 exit(1); 服务器 void user_manage() /用户管理函数 显示初始界面; void *pthread_accept(void *arg) /等待接收 socket 连接线程处理

26、 int sockfd=*(int *)arg; while(1) client_inf.fd=accept_sock(sockfd, pthread_create( void *pthread_handleclient(void *arg)/线程处理函数 判断接收的标记信息 recv_msg(client_inf.fd, 转入到相应处理函数; int reg_check(struct message sock_msg) /核对注册请求 依次从文件中读取信息和接收到的信息相比; 都不相等则追加写入,注册成功; 否则注册失败; int log_check(struct message sock_

27、msg) /核对登陆请求 依次从文件中读取信息和接收到的信息相比; 找到相等,登陆成功; 否则登陆失败; int count(char * a) /计算参数所指定的文件中的记录的个数的函数 if(fp=fopen(a,rb)=null)/只读方式打开指定文件 printf(ncannot open filen); getchar(); return 0; for(i=0;!feof(fp);i+)/循环读取文件内记录直到文件尾 fread( fclose(fp); void handle_input(struct message sock_msg,client_inf client_inf)

28、/服务器信息存 储 将接收到的信息写入文件; fwrite( void handle_delete(struct message sock_msg,client_inf client_inf) /删除信息查找 创建包含学号信息的链表; 在链表中找到待删除的记录和文件中的记录比较; 找到后写入临时文件中,并跳过待删除的记录; for(con=0; condata.fd=server_fd; if (argc!=2) perror(port:); exit(1); server_fd=create_sock(); init_host_addr( if (bind_sock(server_fd,se

29、rver_addr)=-1) perror(bind_sock:n); exit(1); if (listen_sock(server_fd,10)=-1) perror(listen_sock:n); exit(1); pthread_create( user_manage(); return; int reg_check(struct message sock_msg) int fd; int nread,nwrite; struct message user_msg; if(fd=open(user.txt,o_rdwr|o_creat|o_append,0666)0) perror(o

30、pen); return -1; do if(nread=read(fd, close(fd); return -1; if(strcmp(sock_,user_)=0) close(fd); return -1; while(nread = sizeof(struct message); if(nwrite=write(fd, close(fd); return -1; while(nwrite!=sizeof(struct message) lseek(fd,-nwrite,seek_cur); nwrite=write(fd,sock_msg,sizeof

31、(struct message); close(fd); return 0; int log_check(struct message sock_msg) int fd,nread; struct message user_msg; if(fd=open(user.txt,o_rdonly)0) perror(log:open user.txt); return -1; do if (nread=read(fd, close(fd); return -1; if (nread!=sizeof(struct message) return -1; if (strcmp(sock_

32、,user_)=0) return 0; while(nread=sizeof(struct message); close(fd); return -1; void handle_input(struct message sock_msg,client_inf client_inf) file * fp; char temp50; if(fp=fopen(inform.txt,ab) = null) /if(fp=fopen(inform.txt,wb)=null) printf(t 打开信息文件失败!); getchar(); return; if(fwrite( strc

33、py(sock_msg.msg,n write wrong!n); send_msg(client_inf.fd,sock_msg); getchar(); return; strcpy(sock_msg.msg,write succeed!n 继续添加? t1).yest2).no: ); send_msg(client_inf.fd,sock_msg); memset(sock_msg.flag,0,strlen(sock_msg.flag); memset(sock_,0,strlen(sock_); memset(sock_msg.msg,0,strle

34、n(sock_msg.msg); printf(write succeed!n); fclose(fp); int count(char * a)/计算参数所指定的文件中的记录的个数的函数 file *fp; int i; struct message socket_msg; memset(socket_msg.flag,0,strlen(socket_msg.flag); memset(socket_,0,strlen(socket_); memset(socket_msg.msg,0,strlen(socket_msg.msg); if(fp=fopen(a

35、,rb)=null)/只读方式打开指定文件 printf(ncannot open filen); getchar(); return 0; for(i=0;!feof(fp);i+)/循环读取文件内记录直到文件尾 fread( fclose(fp); return(i-1);/返回记录个数 void handle_display(client_inf client_inf) struct message sock_msg; memset(sock_msg.flag,0,strlen(sock_msg.flag); strcpy(sock_, ); memset(sock_ms

36、g.msg,0,strlen(sock_msg.msg); int n=count(inform.txt); int total=0; file *fp; if(fp=fopen(inform.txt,rb) = null) printf(t 打开信息文件失败!); getchar(); exit(1); for(;totaln;) if(fread( getchar(); exit(1); total+; send_msg(client_inf.fd,sock_msg); send_msg(client_inf.fd,sock_msg); fclose(fp); return; void h

37、andle_delete(struct message sock_msg,client_inf client_inf) char no10; strcpy(no,sock_); memset(sock_msg.flag,0,strlen(sock_msg.flag); memset(sock_,0,strlen(sock_); memset(sock_msg.msg,0,strlen(sock_msg.msg); struct node char num10; struct node * next; ; int amount; / 信息文件中的记

38、录总数 int con=0; / 已处理的文件记录总数 struct node node; struct node * head=null, * pf=null, * pb=null; /struct info info, info_temp; struct message sock_student,sock_temp; memset(sock_student.flag,0,strlen(sock_student.flag); memset(sock_,0,strlen(sock_); memset(sock_student.msg,0,strl

39、en(sock_student.msg); memset(sock_temp.flag,0,strlen(sock_temp.flag); memset(sock_,0,strlen(sock_); memset(sock_temp.msg,0,strlen(sock_temp.msg); file * fp, *fp1; / fp 用于指示信息文件 inform,而 fp1 用于指示临时文件 int total=0; int offset=0; / 文件位置指针偏移量 char temp10, temp110; int flag=0; / 指示是否继续进行

40、修改,为 1 时继续 int ord=0; / 待修改的项目指示 int repeat=0; / 在修改中用于重复的输入 int yes=0; / 指示是否保存修改 amount=count(inform.txt); if(fp=fopen(inform.txt,rb) = null) printf(t 打开信息文件失败!); getchar(); exit(1); for(con=0; connum,sock_); if(total=0) head=pf=pb; else pf-next=pb; pb-next=null; pf=pb; total+; fclose(

41、fp); pf=head; while(strcmp(pf-num,no) offset+; if(!strcmp(pf-num,no) / 待删除的记录存在 if(fp=fopen(inform.txt,rb)=null) printf(nn 文件打开失败!); getchar(); exit(1); if(fp1=fopen(inform_temp.txt,wb)=null) printf(nn 文件打开失败!); getchar(); exit(1); total=0; amount=count(inform.txt); for(con=0; conamount; con+) / onl

42、y one if(con=offset) fseek(fp,(long)sizeof(struct message),1);continue; fread( fwrite( fclose(fp1); fclose(fp); if(fp1=fopen(inform_temp.txt,rb)=null) printf(nn 文件打开失败!); getchar(); exit(1); if(fp=fopen(inform.txt,wb)=null) printf(nn 文件打开失败!); getchar(); exit(1); amount=count(inform_temp.txt); for(c

43、on=0; conamount; con+) fread( fwrite( fclose(fp); fclose(fp1); strcpy(sock_temp.flag,yes); strcpy(sock_temp.msg,n 已删除.nn); printf(已删除学生: %sn,no); send_msg(client_inf.fd,sock_temp); else / 待删除的记录不存在 strcpy(sock_temp.flag,no); strcpy(sock_temp.msg,n 记录不存在! 任意建继续.nn); send_msg(client_inf.fd,sock_temp);

44、 memset(sock_student.flag,0,strlen(sock_student.flag); memset(sock_,0,strlen(sock_); memset(sock_student.msg,0,strlen(sock_student.msg); memset(sock_temp.flag,0,strlen(sock_temp.flag); memset(sock_,0,strlen(sock_); memset(sock_temp.msg,0,strlen(sock_temp.msg

45、); void handle_update(struct message sock_msg,client_inf client_inf) char no10; strcpy(no,sock_); struct message sock_student,sock_temp; struct node char num10; struct node * next; ; int amount; / 信息文件中的记录总数 int con=0; / 已处理的文件记录总数 struct node node; struct node * head=null, * pf=null, * pb=n

46、ull; file * fp; int total=0; long offset=0; / 文件位置指针偏移量 char temp10, temp110; int flag=0; / 指示是否继续进行修改,为 1 时继续 int ord; / 待修改的项目指示 int repeat; / 在修改中用于重复的输入 int yes=0; / 指示是否保存修改 char choice=0; amount=count(inform.txt); if(fp=fopen(inform.txt,rb) = null) printf(t 打开信息文件失败!); getchar(); exit(1); for(

47、con=0; connum,sock_); if(total=0) head=pf=pb; else pf-next=pb; pb-next=null; pf=pb; total+; fclose(fp); pf=head; offset=0; while(strcmp(pf-num,no) offset+; if(!strcmp(pf-num,no) if(fp=fopen(inform.txt,rb+)=null) printf(nn 文件打开失败!); getchar(); exit(1); offset *= sizeof(struct message); /

48、使文件位置指针移动到待修改记录处 rewind(fp); if(fseek(fp, offset, 0) != 0) printf(nn 文件操作失败 !); getchar(); exit(1); recv_msg(client_inf.fd, /printf(%s,%sn,sock_,sock_student.msg); if(fwrite( strcpy(sock_student.flag,yes); strcpy(sock_student.msg,已修改.); send_msg(client_inf.fd,sock_student); else printf(修

49、改失败 ! n); strcpy(sock_student.flag,no); strcpy(sock_student.msg,修改失败 !); send_msg(client_inf.fd,sock_student); fclose(fp); else strcpy(sock_student.msg,记录不存在! 是否修改其它记录?:tt1).yest2).no); send_msg(client_inf.fd,sock_student); void handle_select(struct message sock_msg,client_inf client_inf) char no10;

50、 strcpy(no,sock_); struct message sock_student; struct node char num10; struct node * next; ; int amount; / 信息文件中的记录总数 int con=0; / 已处理的文件记录总数 struct node node; struct node * head=null, * pf=null, * pb=null; /struct info info, info_temp; file * fp; int total=0; long offset=0; / 文件位置指针偏移量 cha

51、r temp10, temp110; int flag=0; / 指示是否继续进行修改,为 1 时继续 int ord; / 待修改的项目指示 int repeat; / 在修改中用于重复的输入 int yes=0; / 指示是否保存修改 char choice=0; amount=count(inform.txt); if(fp=fopen(inform.txt,rb) = null) printf(t 打开信息文件失败!); getchar(); exit(1); for(con=0; connum,sock_); if(total=0) head=pf=pb; e

52、lse pf-next=pb; pb-next=null; pf=pb; total+; fclose(fp); pf=head; offset=0l; while(strcmp(pf-num,no) offset+; if(!strcmp(pf-num,no) / 待修改的记录存在 if(fp=fopen(inform.txt,rb)=null) printf(nn 文件打开失败!); getchar(); exit(1); offset *= sizeof(struct message); / 使文件位置指针移动到待修改记录处 rewind(fp); if(fseek(fp, offset, 0) != 0) printf(nn 文件操作失败 !); getchar(); exit(1); if(fread( send_msg(client_inf.fd,sock_studen

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论