用一个数组来存放连接的客户端的sockid,一个COUNT来存放当前连接的客户端数量。服务端listen后一直处在accept状态,每接收到一个连接,就创建一个线程来完成与客户端的通信。当一个客户端发言时就遍历存放sockid的数组,向其它所有用户发送这条信息。
客户端
连接服务端后启动一个线程专门接收服务端返回的信息,主线程专门负责向服务端发送消息。/*头文件*/
#ifndef _PUBLIC_H
#define _PUBLIC_H
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
#粤嵌科技#
#endif


客户端
连接服务端后启动一个线程专门接收服务端返回的信息,主线程专门负责向服务端发送消息。/*头文件*/
#ifndef _PUBLIC_H
#define _PUBLIC_H
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
#粤嵌科技#
#endif

