forked from guilherme-ls/SocketsHandler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sockets.hpp
52 lines (37 loc) · 1.24 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/10server.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 mess)
: send_to { std::move(send) }
, sent_from { std::move(sent) }
, message { std::move(mess) }
{};
};
static int connection_socket;
public:
static void start();
static void openSocket(std::string name);
static void listenClient(SocketHandler::Message* com);
static void listenServer(int* sockets, std::string* connection_list, int size);
static void sendMessage(Message com);
static void transfer(Message com, int* sockets, int size);
static Message strToMsg(char* com);
static int getId(std::string name, std::string* name_list, int size);
static void closeSocket(int dis_socket);
};