-
大小: 77KB文件類型: .rar金幣: 2下載: 0 次發(fā)布日期: 2023-04-07
- 語言: 其他
- 標(biāo)簽: linux??聊天室??C語言??網(wǎng)絡(luò)編程??
資源簡介
實(shí)現(xiàn)目標(biāo)
一個(gè)在Linux下可以使用的聊天軟件,要求至少實(shí)現(xiàn)如下功能:
1. 采用Client/Server架構(gòu)
2. Client A 登陸聊天服務(wù)器前,需要注冊自己的ID和密碼
3. 注冊成功后,Client A 就可以通過自己的ID和密碼登陸聊天服務(wù)器
4. 多個(gè)Client X 可以同時(shí)登陸聊天服務(wù)器之后,與其他用戶進(jìn)行通訊聊天
5. Client A成功登陸后可以查看當(dāng)前聊天室內(nèi)其他在線用戶Client x
6. Client A可以選擇發(fā)消息給某個(gè)特定的Client X,即”悄悄話”功能
7. Client A 可以選擇發(fā)消息全部的在線用戶,即”群發(fā)消息”功能
8. Client A 在退出時(shí)需要保存聊天記錄
9. Server端維護(hù)一個(gè)所有登陸用戶的聊天會(huì)的記錄文件,以便備查
可以選擇實(shí)現(xiàn)的附加功能:
1. Server可以內(nèi)建一個(gè)特殊權(quán)限的賬號(hào)admin,用于管理聊天室
2. Admin可以將某個(gè)Client X “提出聊天室”
3. Admin可以將某個(gè)Client X ”設(shè)為只能旁聽,不能發(fā)言”
4. Client 端發(fā)言增加表情符號(hào),可以設(shè)置某些自定義的特殊組合來表達(dá)感情.如輸入:),則會(huì)自動(dòng)發(fā)送”XXX向大家做了個(gè)笑臉”
5. Client段增加某些常用話語,可以對其中某些部分進(jìn)行”姓名替換”,例如,輸入/ClientA/welcome,則會(huì)自動(dòng)發(fā)送”ClientA 大俠,歡迎你來到咱們的聊天室”
附加功能:
文件傳輸

代碼片段和文件信息
#include?“../../include/client_handle.h“
/***************************************************
函數(shù)名:admin_chat
功能:管理員聊天功能
傳入?yún)?shù):int?sockfdstruct?message?*a
返回值:退出返回FAULT
***************************************************/
int?admin_chat(int?sockfdstruct?message?*a)??
{
????char?str[MAXLEN];
????char?buf[MAXLEN];
????time_t?timep;
????sprintf(chat_log“./chat_log/%s.txt“(*a).name);
????if((fd=my_open(chat_logO_RDWR|O_CREAT|O_APPEND0777))?0)
????{
????????printf(“打開聊天記錄失敗!“);
exit(1);
????}
????setbuf(stdinNULL);
????my_strcpy((*a).flag“all“);
????printf(“尊敬的%s你好,如需幫助請輸入:.help\n“l(fā)ocname);
????while(1)
{
memset((*a).msg0strlen((*a).msg));
memset(str0strlen(str));
usleep(100000);
printf(“TO?%s:\n“(*a).flag);
setbuf(stdinNULL);
gets(str);
if(OK?==?help(str))??????????????????????//提示信息??
{
????continue;
}
my_strcpy((*a).namelocname);
my_strcpy(buf(*a).flag);
cutStr(str(*a).flag15(*a).msgMAXLEN‘$‘);????//調(diào)用字符切割函數(shù)??
expression((*a).name(*a).msg);???????????????//表情替換函數(shù)?
common_use_words((*a).msg);????????????????????//常用語使用函數(shù)
if(my_strcmp((*a).flag“exit“)?==?0)
{
????return?FAULT;
}
if(my_strcmp((*a).flag“view“)?==?0)???????????
{
????my_send(sockfdasizeof((*a))0);???????//請求查看在線用戶
????? ????my_strcpy((*a).flagbuf);
????continue;
}
if(my_strcmp((*a).flag“all“)?==?0)
{
????my_send(sockfdasizeof(*a)0);????????
????continue;
}
????????if?((my_strcmp((*a).flag“trans“)?==?0)?&&?(savefilefd?<=0))
{
???? ????if?((my_strcmp((*a).msg“agree“)?==?0)?&&?(savefilefd?==?0))
????{
????????char?savefilename[MAXLEN];
my_strcpy((*a).addresseefilefromuser);
printf(“請輸入你想保存的文件名:\n“);
do
{
????setbuf(stdinNULL);
????gets(savefilename);
????savefilefd?=?open(savefilenameO_RDWR|O_CREAT|O_EXCL0777);
????if(savefilefd?==?-1)
????{
????????printf(“文件已存在,你重新輸入:\n“);
????}
}while(savefilefd?==?-1);
if(savefilefd?0)
{
????printf(“接收文件失敗!\n“);
????savefilefd?=?-1;
}
else
{
????my_strcpy((*a).msg“agree“);
????my_send(sockfdasizeof(*a)0);
????printf(“文件接收中……\n“);
}
}
else
{
memset(str0strlen(str));
cutStr((*a).msg(*a).addressee20strMAXLEN‘$‘);
if?(str[0]?!=?‘\0‘?&&?(*a).addressee[0]?!=?‘\0‘)
{
char?transfileallname[22];
sprintf(transfileallname“./%s“str);
savefilefd?=?open(strO_RDWR0666);
if(savefilefd?0)
{
printf(“打開文件失敗!\n“);
savefilefd?=?-1;
}
???????? else
{
memset((*a).msg0strlen((*a).msg));
my_strcpy((*a).msgstr);
my_send(sockfdasizeof(*a)0);
}
}
else
{
my_strcpy((*a).msg“disagree“);
my_strcpy((*a).namelocname);
my_strcpy((*a).addresseefilefromuser);
my_send(sockfdasizeof(*a)0);
}
}
my_strcpy((*a).flagbuf);
continue;
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????590??2012-08-02?15:35??Linux下C實(shí)現(xiàn)的聊天室\client\admin
?????文件??????23525??2012-08-02?15:30??Linux下C實(shí)現(xiàn)的聊天室\client\client
?????文件???????1638??2012-08-07?12:41??Linux下C實(shí)現(xiàn)的聊天室\client\include\client_handle.h
?????文件????????927??2012-08-07?12:42??Linux下C實(shí)現(xiàn)的聊天室\client\include\client_main.h
?????文件????????327??2012-07-31?15:17??Linux下C實(shí)現(xiàn)的聊天室\client\include\my_system_call.h
?????文件????????115??2012-08-01?21:01??Linux下C實(shí)現(xiàn)的聊天室\client\makefile
?????文件???????1499??2012-08-01?20:59??Linux下C實(shí)現(xiàn)的聊天室\client\sc
?????文件???????6921??2012-08-02?00:44??Linux下C實(shí)現(xiàn)的聊天室\client\src\admin\admin.c
?????文件???????6336??2012-08-02?15:30??Linux下C實(shí)現(xiàn)的聊天室\client\src\admin\admin.o
?????文件????????125??2012-08-01?18:23??Linux下C實(shí)現(xiàn)的聊天室\client\src\admin\makefile
?????文件???????2543??2012-08-07?12:44??Linux下C實(shí)現(xiàn)的聊天室\client\src\client_main\client_main.c
?????文件???????2520??2012-08-02?00:00??Linux下C實(shí)現(xiàn)的聊天室\client\src\client_main\client_main.o
?????文件????????142??2012-08-01?18:23??Linux下C實(shí)現(xiàn)的聊天室\client\src\client_main\makefile
?????文件???????2081??2012-08-01?18:20??Linux下C實(shí)現(xiàn)的聊天室\client\src\handlefile\handlefile.c
?????文件???????2224??2012-08-02?00:00??Linux下C實(shí)現(xiàn)的聊天室\client\src\handlefile\handlefile.o
?????文件????????141??2012-08-01?18:22??Linux下C實(shí)現(xiàn)的聊天室\client\src\handlefile\makefile
?????文件???????4055??2012-08-01?18:24??Linux下C實(shí)現(xiàn)的聊天室\client\src\handlerecvmsg\handlerecvmsg.c
?????文件???????4108??2012-08-02?00:00??Linux下C實(shí)現(xiàn)的聊天室\client\src\handlerecvmsg\handlerecvmsg.o
?????文件????????150??2012-08-01?18:24??Linux下C實(shí)現(xiàn)的聊天室\client\src\handlerecvmsg\makefile
?????文件???????2792??2012-08-01?18:26??Linux下C實(shí)現(xiàn)的聊天室\client\src\handlestr\handlestr.c
?????文件???????2244??2012-08-02?00:00??Linux下C實(shí)現(xiàn)的聊天室\client\src\handlestr\handlestr.o
?????文件????????138??2012-08-01?18:26??Linux下C實(shí)現(xiàn)的聊天室\client\src\handlestr\makefile
?????文件???????1616??2012-08-01?18:27??Linux下C實(shí)現(xiàn)的聊天室\client\src\interface\interface.c
?????文件???????2212??2012-08-02?00:00??Linux下C實(shí)現(xiàn)的聊天室\client\src\interface\interface.o
?????文件????????138??2012-08-01?18:27??Linux下C實(shí)現(xiàn)的聊天室\client\src\interface\makefile
?????文件???????4757??2012-08-01?23:08??Linux下C實(shí)現(xiàn)的聊天室\client\src\log\log.c
?????文件???????5452??2012-08-02?00:00??Linux下C實(shí)現(xiàn)的聊天室\client\src\log\log.o
?????文件????????120??2012-08-01?18:28??Linux下C實(shí)現(xiàn)的聊天室\client\src\log\makefile
?????文件?????????74??2012-08-01?18:31??Linux下C實(shí)現(xiàn)的聊天室\client\src\my_str\makefile
?????文件???????1224??2012-08-02?00:32??Linux下C實(shí)現(xiàn)的聊天室\client\src\my_str\my_str.c
............此處省略89個(gè)文件信息
評論
共有 條評論