blob: a5794e948e960d564184ef612b7da176c1d0ffb8 (
plain)
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
|
#pragma once
// For encryption wrappers.
#include <Security/Encryption.hpp>
// WinSocks
#include <winsock2.h>
#pragma comment(lib, "ws2_32.lib")
// std::min
#include <algorithm>
// std::unique_ptr
#include <memory>
namespace Networking
{
// A TCPClient is essentially the same as the TCPConnection counterpart on the server,
// however, it independently handles connection.
class TCPClient
{
WSADATA m_WinSocks;
SOCKET m_Socket;
sockaddr_in m_Context;
uint8_t m_EncryptionKey[32];
public:
TCPClient() = default;
// Connects to a remote server.
// Also handles the initial handshake between server and client.
bool Start(uint32_t ServerAddress, uint16_t ServerPort);
// Kills the client.
void Kill();
// Wrappers for sending/receiving data.
void SendRawBytes(ByteArray &Bytes);
ByteArray ReceiveRawBytes();
void SendBytes(ByteArray &Bytes);
ByteArray ReceiveBytes();
};
using TCPClientPtr = std::unique_ptr<TCPClient>;
}
|