-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathudp_server.h
44 lines (40 loc) · 926 Bytes
/
udp_server.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef _UDP_SERVER_H_
#define _UDP_SERVER_H_
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <sys/types.h>
#include <sys/socket.h>
#include <pthread.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <fcntl.h>
#include "log.h"
#include "pool.h"
#include "data.h"
class udp_server
{
public:
udp_server(const std::string& _ip,int port);
int init_server();
int recv_msg(std::string& out);
int send_msg(const std::string& in,struct sockaddr_in& peer,\
const socklen_t& len);
//广播消息
int brocast_msg();
//添加用户,删除用户
int add_online_user(struct sockaddr_in *client);
int del_online_user(struct sockaddr_in *client);
~udp_server();
private:
udp_server(const udp_server&);
private:
std::string ip;
int port;
int sock;
//用户数据表
std::map<int,struct sockaddr_in> online_user;
pool data_pool;//数据池是一个vector<string>
};
#endif