linux上的一个简单的多人聊天室.
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
linux 上的一个简单的多人聊天室 002 i.h is a used for creating a library 003 for server client
004 Mar 18 2010
005
006
007 #ifndef _I_H
008
009 #define _I_H
010
011 #include math.h
012 #include stdio.h
013 #include syssocket.h
014 #include arpainet.h
015 #include netinetin.h
016 #include unistd.h
017 #include systypes.h
018 #include sysstat.h
019 #include fcntl.h
020 #include stdlib.h
021 #include errno.h
022 #include string.h
023 #include inttypes.h
024 #include time.h
025 #include sysioctl.h
026 #include netif.h
027 #include signal.h
028 #include ncurses.h
029 #include math.h
030
031 #define SEVR_IP 127.0.0.1
032 #define SEVR_PORT 8081
033 #define CNTNT_LEN 150
034 #define MSG_LEN sizeof(struct msg 035 #define ADDR_LEN sizeof(struct sockaddr 036 #define USR_LEN sizeof(struct user
037 #define PRT_LEN 8
038 #define HSTR_LEN sizeof(struct chat_history 039
040 declare Global variables
041 int mainfd; used as chat histroy file handle
042 int sockfd; used as socket local handle
043 int count;
044 struct sockaddr_in server;
045
046 msg is used for communicating message
047 struct msg
048 {
049 int flag; flag meaning1,ordinary; 2,log msg; 3,reg msg, other,file 050 int id_from;
051 int id_to;
052 char content[CNTNT_LEN];
053 char append[10];
054 };
055
056 user is used information list
057 struct user
058 {
059 int id;
060 char name[10];
061 char password[10];
062 char p_chatlog;
063 struct sockaddr user_addr;
064 };
065 chat_history used for reading chat history
066 struct chat_history
067 {
068 char content[CNTNT_LEN];
069 char time[25];
070 int to;
071 int from;
072 int count;
073 };
074
075 i_functions below is funtions needed by both client and sever 076 extern int i_saveto_chat(struct msg pmsg;
077
078 int i_clean_stdin (
079 {
080 while ('n' == getchar(
081 {
082 continue;
083 }
084
085 return(0;
086 }
087
088 int i_print(char pmsg, int size 089 {
090 int i = 1;
091
092 for (i; i= size; i++
093 {
094 if (pmsg != 'n' 095 {
096 printf(%c, pmsg; 097 pmsg ++; 098 }
099 else
100 {
101 return(0;
102 }
103 }
104
105 return(0;
106 }
107 int i_input(char p_input
108 {
109 char c = '0';
110 int i;
111
112 for (i = 0; i CNTNT_LEN; i++ 113 {
114 p_input[i] = getchar(;
115 if (p_input[i] =='n'
116 {
117 return(0;
118 }
119 }