-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocket.h
More file actions
45 lines (37 loc) · 785 Bytes
/
Socket.h
File metadata and controls
45 lines (37 loc) · 785 Bytes
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
#pragma once
#ifdef WIN32 // windows
#include <WinSock2.h>
#include <WS2tcpip.h>
using socket_t = SOCKET;
#else // POSIX
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <cstring>
#include <unistd.h>
#include <errno.h>
using socket_t = int;
constexpr int INVALID_SOCKET = -1;
constexpr int SOCKET_ERROR = -1;
#endif
#include <iostream>
#include <string>
#include "spdlog/spdlog.h"
class Socket
{
public:
Socket();
Socket(socket_t sock);
~Socket();
void Bind(const char* iNode, const char* iPort);
void Listen(int backlog);
std::string Recv(int bytesToRecv);
Socket Accept();
void Send(const std::string& sendString);
void CloseSocket();
void Shutdown();
private:
socket_t m_Sockfd = INVALID_SOCKET;
size_t iResult;
int GetLastError();
};