linux qq多进程客户端,基于多进程QQ聊天软件设计.doc

基于多进程QQ聊天软件设计

基于多进程的QQ聊天程序设计功能需求描述用户名登陆聊天,人与人之间交流是必不可少的。私聊,与特定的用户聊天群聊,向所有的用户发送消息,大家一起聊欢乐多

server端 输入:各客户端发来的消息。 输出:向各个客户端的私有消息队列发送消息Client端 输入:a,键盘输入。 b,server端发来的消息

主要应用到了C语言里的 消息队列、管道、数据结构链表的建立、插入、遍历等

程序测试截图

/*头文件*/#ifndef __INCLUDE_H__#define __INCLUDE_H__

#include#include#include#include#include#include#include#include#include

/*enum _msg_type{MSG_TYPE_MIN = 0,MSG_TYPE_INPUT,MSG_TYPE_STRING,MSG_TYPE_TEST,MSG_TYPE_MAX} msg_type;*//*struct message{long msg_type;char msg_text[BUFSIZ];};*/struct msg_server{ //消息结构体long mytype; // 消息类型,我用的是发送消息的进程号int my_msgid; //客户端的私有消息队列号 char myname[10]; //客户端用户姓名char aim_name[10]; //此条消息将要发送的对象char text[BUFSIZ]; //消息正文struct msg_server *next; //链表节点连接指针};/*struct msg_land{int type;int pid;int msgid;char name[10];};

struct msg_chat{int pid;int msgid;char name[10];char aim_name[10];char text[BUFSIZ];};*/#endif

/*服务器*/#include"include.h"

static int pid; //进程号static struct msg_server *Lp; //测试用的static int len; //消息长度static struct msg_server buf; //父进程向子进程通过管道发送消息的缓冲区static struct msg_server buf_c; //子进程通过管道接收消息缓存区static struct msg_server *ps;

static struct msg_server msg_rcv; //父进程通过消息队列接收消息缓存区static struct msg_server *L; static struct msg_server *Q; static int com_qid; //公共消息队列号static int flag; //判断是不是登陆信息的标志static struct msg_server *tmp; //用于遍历的临时结构体循环变量 static key_t key; static int pfd[2]; //用于管道通信的文件标识符static struct msg_server *H; //众所周知的消息队列链表头static char offline[]=" 对不起,您找的用户不在线.\n请输入quit重新选择聊天对象\n";

/*SIGINT信号处理,删除消息队列,关闭管道文件*/void my_func(int sign_no){if(sign_no == SIGINT){if(msgctl(com_qid,IPC_RMID,NULL) < 0 ){perror("msgctl");exit(1);}close(pfd[0]);close(pfd[1]);_exit(1);}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值