-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsockets.hpp
52 lines (37 loc) · 1.27 KB
/
sockets.hpp
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
45
46
47
48
49
50
51
52
#pragma once
#include <exception>
#include <map>
#include <string>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#define SOCKET_NAME "/tmp/server.socket"
#define STD_SIZE 128
class SocketHandler {
public:
struct Message {
std::string send_to;
std::string sent_from;
std::string message;
Message() = default;
Message(std::string send, std::string sent, std::string msg)
: send_to { std::move(send) }
, sent_from { std::move(sent) }
, message { std::move(msg) }
{};
};
static int connection_socket;
public:
static int start();
static int openSocket(std::string name);
static int listenClient(SocketHandler::Message* com, struct timeval dropout_time);
static int listenServer(int* sockets, std::string* connection_list, int size, SocketHandler::Message* server_com, struct timeval dropout_time);
static int sendMessage(int socket, Message com);
void closeSocket(int dis_socket);
private:
static int transfer(Message com, int* sockets, int size);
Message strToMsg(char* com);
};