• 大小: 1.17MB
    文件类型: .zip
    金币: 2
    下载: 0 次
    发布日期: 2024-01-26
  • 语言: 其他
  • 标签: linux  网络  c  

资源简介

此聊天室是本人闲暇时候所写。采用tcp网络通讯,无界面,在linux下运行。其功能有:群聊、私聊、传送文件以及超级用户的禁言、解禁以及踢人功能。

资源截图

代码片段和文件信息

#include “main.h“
/*************************************************************
函数名:chat
功能:普通用户发送消息
输入参数:无
返回值:无
作者:马健
*************************************************************/
void chat()
{
    mes mesg;
    printf(“欢迎登录聊天室,(你可以输入help查阅帮助)祝你聊天愉快!\n“);
while(1)
{
    char buf[1024];
        scanf(“%s“ buf);
        //printf(“请输入指令!\n“);
        /*打印帮助文档*/
        if(strcmp(buf “help“) == 0)
        {
            logo();
        }
        /*选择进行私聊*/
        else if(strcmp(buf “prvt“) == 0)
        {
            while(1)
            {
                printf(“请输入对方用户名:\n“);
                char name[20];
                scanf(“%s“name);
                strcpy(mesg.namemsg.name);
                strcpy(mesg.to name);

                while(1)
                {
                    memset(buf ‘\0‘ sizeof(buf));
                    scanf(“%s“ buf);

                    /*输入‘q’退出私聊*/
                    if(strcmp(buf“q“) == 0)
                    {
                        printf(“已退出私聊模式!输入help查看帮助!\n“);
                        break;
                    }
                    /*接收文件*/
                    else if(strcmp(buf“y“) == 0)
                    {
                        if(msg.type == 2)
                        {
                            printf(“请输入保存文件的路径:\n“);
                            scanf(“%s“msg.file_name);
                            int *p;
                            p = &msg.isrecv;
                            *p = 1;

                            mesg.flag = 8;
                            mesg.type = 3;
                            mesg.isrecv = 1;
                            strcpy(mesg.tomsg.to);
                            strcpy(mesg.namemsg.name);
                            write(sockfd&mesgsizeof(mesg));
                        }
                        else
                        {
                            time_t t;
                            time(&t);
                            strcpy(mesg.mess ctime(&t));
                            mesg.flag = 2;
                            mesg.type = 1;
                            strcpy(mesg.to “all“);
                            strcat(mesg.mess msg.name);
                            strcat(mesg.mess “:“);
                            strcat(mesg.mess buf);
                            if((write(sockfd &mesg sizeof(mesg))) == -1)
                            {
                                fprintf(stderr “Write Error:%s\n“ strerror(errno));
                                exit(1);
                            }
                        }
                    }
                    /*不接收文件*/
                    else if(strcmp(buf“n“) == 0)
                    {
                        if(msg.type == 2)
                        {
                            int *p;
                            p = &msg.isrecv;
                            *p = 2;

                  

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2011-10-25 14:56  1--chatroom\
     目录           0  2011-10-25 14:55  1--chatroom\chatroom\
     目录           0  2012-03-21 09:42  1--chatroom\chatroom\client\
     目录           0  2012-03-08 10:44  1--chatroom\chatroom\client\bin\
     文件       21658  2012-03-08 10:44  1--chatroom\chatroom\client\bin\client
     目录           0  2011-10-25 14:55  1--chatroom\chatroom\client\include\
     文件          33  2011-10-14 23:47  1--chatroom\chatroom\client\include\chat.h
     文件         531  2011-10-12 23:39  1--chatroom\chatroom\client\include\infomation.h
     文件          33  2011-10-14 23:45  1--chatroom\chatroom\client\include\logo.h
     文件         388  2011-10-14 23:50  1--chatroom\chatroom\client\include\main.h
     文件          57  2011-10-14 23:44  1--chatroom\chatroom\client\include\save.h
     文件          40  2011-10-14 23:47  1--chatroom\chatroom\client\include\super_login.h
     文件          39  2011-10-14 23:46  1--chatroom\chatroom\client\include\super_logo.h
     文件          71  2012-03-08 10:53  1--chatroom\chatroom\client\makefile
     目录           0  2012-03-21 09:42  1--chatroom\chatroom\client\src\
     文件       15858  2011-10-14 23:41  1--chatroom\chatroom\client\src\chat.c
     文件         643  2012-03-08 10:48  1--chatroom\chatroom\client\src\logo.c
     文件        9830  2012-03-08 10:48  1--chatroom\chatroom\client\src\main.c
     文件          71  2012-03-08 10:55  1--chatroom\chatroom\client\src\makefile
     文件         405  2011-10-14 23:37  1--chatroom\chatroom\client\src\save.c
     文件        3127  2011-10-14 23:41  1--chatroom\chatroom\client\src\super_login.c
     文件         513  2011-10-14 23:39  1--chatroom\chatroom\client\src\super_logo.c
     目录           0  2012-03-12 14:15  1--chatroom\chatroom\server\
     目录           0  2012-03-12 14:15  1--chatroom\chatroom\server\bin\
     文件         203  2011-10-15 19:33  1--chatroom\chatroom\server\bin\aaa
     文件          61  2011-10-17 20:46  1--chatroom\chatroom\server\bin\aaaa
     文件         185  2012-03-12 14:15  1--chatroom\chatroom\server\bin\dddd
     文件         211  2011-10-20 01:20  1--chatroom\chatroom\server\bin\majian
     文件         101  2011-10-17 20:50  1--chatroom\chatroom\server\bin\qqq
     文件       15473  2011-10-15 00:48  1--chatroom\chatroom\server\bin\server
     文件           0  2011-10-17 20:38  1--chatroom\chatroom\server\bin\test.txt
............此处省略37个文件信息

评论

共有 条评论