Linux Linux函数 Linux聊天程序 基于socket的TCP(有连接的)聊天程序
2012-05-22 22:58
525 查看
/*在此只付上头文件,如需要去我的资源下载。
http://download.csdn.net/detail/ta893115871/4322905
O(∩_∩)O谢谢
暂时实现的功能有:
1.群聊
2.私聊
3.登陆验证
4.注册
5.所用的在线用户
6.退出
7.管理员踢出某用户
8.管理员禁止某用户聊天
9.管理员提升某用户为管理员
10.管理员把某用户降为普通用户
*/
http://download.csdn.net/detail/ta893115871/4322905
O(∩_∩)O谢谢
暂时实现的功能有:
1.群聊
2.私聊
3.登陆验证
4.注册
5.所用的在线用户
6.退出
7.管理员踢出某用户
8.管理员禁止某用户聊天
9.管理员提升某用户为管理员
10.管理员把某用户降为普通用户
*/
/* Author QQ: 893115871 Author Email:gfj19900401@163.com 头文件,函数声明和宏定义 */ #ifndef CHAT_H #define CHAT_H #include<stdio.h> #include<stdlib.h> #include<string.h> #include<sys/types.h> #include<sys/socket.h> //#include<linux/in.h> #include<arpa/inet.h> #include<pthread.h> #include<fcntl.h> #include<sys/stat.h> #include<sys/types.h> #include<signal.h> #include<time.h> //for asctime() and time() #include<ctype.h> //for ispunct() #define QUEUELEN 100 //max of client #define BUF_SIZE 256 //#define IP "127.0.0.1" #define IP "192.168.1.101" //remote ip #define PORT 1234 // port #define FILENAME "userinfo" // file name for save users info(name:passwd:id:authority) #define CLIENT_ID 1000 // client id //========================functions================================================ #define PUBLIC_CHAT 1 //群聊 #define PRIVATE_CHAT 2 //私聊 #define CLIENT_LOGIN 3 //登陆验证 #define CLIENT_REGISTER 4 //注册 #define CLIENT_ONLINE 5 //所用的在线用户 #define CLIENT_EXIT 6 //退出 #define ADMIN_KICK_CLIENT 7 //管理员踢出某用户 #define ADMIN_SHUTUP_CLIENT 8 //管理员禁止某用户聊天 #define ADVANCED_CLIENT_TO_ADMIN 9 //管理员提升某用户为管理员 #define DROP_CLIENT_TO_NORMAL 10 //管理员把某用户降为普通用户 //==================================================================== #define NORMAL_USER_LOGIN_FAILED 0 //普通用户登录失败 #define NORMAL_USER_LOGIN_SUCCESS 1 //普通用户登录成功 #define NORMAL_USER_LOGIN_FAILED_ONLINE 2 //普通用户已经在线 #define ADMIN_LOGIN_SUCCESS 3 //管理员登录成功 #define NORMAL_USER_LOGIN_PASSWD_ERROR 4 //普通用户登录密码错误 #define REGIST_FALIED 0 //注册失败 #define REGIST_EXITED 1 //注册的用户已经存在 #define NORMAL_USER 0 //普通用户 #define ADMIN_USER 1 //管理员 // ===========client attr========================================== typedef struct{ pthread_t tid; //线程的描述符 int sockfd; //accept的返回的客户端的新的套接字描述符 char client_name[25]; // 账号 char client_passwd[25]; //密码 int client_id; //用户ID int is_online; // 在线状态 1 在线 0 不在线 int admin; //用户权限,1为管理员,0为普通用户 }client_info; client_info clients[QUEUELEN]; //===========客户发送的数据结构===================================== typedef struct send_info{ int type; //类型 char id[25]; //对方id char buf[BUF_SIZE]; //内容 char name[25]; //用户名(昵称) char passwd[25]; //密码 }send_info; //================函数功能的协议==================================== typedef struct { int fun_flag; //function flag void (*fun)();// function pointer variable }proto; //====================debug============================ #define CHAT_DEBUG #ifdef CHAT_DEBUG #define DEBUG(message...) fprintf(stderr, message) #else #define DEBUG(message...) #endif // ========fun=========client.c==================== void print_err(char *msg); void reg_log(); void register_client(); void login(); void init_conn(); void writefun(); void show_menu(); void wait_minutes(); void signHandler(int signNo); // ======fun=======server.c====================== int system_init(); void connect_to_client(int socketfd ); void err(char *err_msg); int init_clents(char *tok_file[]); void register_new_client(send_info *send,int newfd); void server_check_login(send_info *send,int newfd); void client_exit(send_info *send,int newfd); int get_sockfd(char dest[]); void private_chat ( send_info *send,int newfd); void public_chat (send_info *send ,int newfd); void get_all_online_clients (send_info *send ,int newfd); void admin_kick_client (send_info *send,int newfd); void admin_shutup_client(send_info *send,int newfd); void advanced_client_to_admin (send_info *send,int newfd); void drop_client_to_normal (send_info *send,int newfd) ; int admin_is_opt_self(send_info *send,int newfd); int admin_opt_self(send_info *send,int newfd); #endif
相关文章推荐
- Linux Linux函数 Linux聊天程序 基于socket的TCP(有连接的)聊天程序
- 基于Linux的Socket编程之TCP全双工Server-Client聊天程序
- 利用TCP和UDP协议,实现基于Socket的小聊天程序(初级版)
- java实现基于Tcp的socket聊天程序
- 基于Linux的Socket编程之TCP全双工Server-Client聊天程序
- 利用TCP和UDP协议,实现基于Socket的小聊天程序
- 基于Linux的SOCKET编程之TCP半双工Client-Server聊天程序
- 基于Linux的SOCKET编程之TCP半双工Client-Server聊天程序
- Java基于Tcp的socket聊天程序
- 利用TCP传输协议实现基于Socket的聊天程序
- C++基于socket的单线程服务器客户端聊天程序(TCP)
- 基于Tcp通信的聊天程序微风IM(c#开源) -技术分析(三) 客户端下线
- 基于TCP的Socket连接【Delphi版】
- Qt实用技巧:基于tcp的C/S构架多人聊天程序(在线、离线、离线信息再次登录后发送等)
- day23网络编程UDP,TCP。IP。DatagramSocket。DatagramPacket。聊天程序。TCP传输。文本转换服务器。
- 基于C#的异步Socket程序(TCP)
- 详解基于java的Socket聊天程序——服务端(附demo)
- 基于TCP(面向连接)的socket编程
- 基于socket的简单聊天程序(一)