程序要求:
有服务器端与客户端,主要功能是实现客户之间的群聊功能,具体是客户端发送消息给服务器端,服务器端转发消息给所有的客户端,服务器端与客户端能够显示客户上线,聊天和离线等功能,主要是采用消息队列;
程序如下:
(1)server.c:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <signal.h>
#include <errno.h>
//消息次类型
#define CLIENT_LOGIN 100
#define CLIENT_CHAT 200
#define CLIENT_QUIT 300
#define SERVER_CHAT 400
#define SERVER_QUIT 500
//消息主类型,用于消息队列类型
#define CLIENT_MSG 1000
#define SERVER_MSG 2000
//链表节点,用于存储上线用户信息
struct node
{
pid_t pid; //客户端的进程号
char name[20];
struct node *next;
};
/