Added initialization, data type defenitons and started with TcpClient

This commit is contained in:
xX-TheDoctor-Xx
2016-07-16 23:26:56 +01:00
parent d9be5d3f2b
commit 97262ee8c6
20 changed files with 595 additions and 36 deletions

47
include/TcpClient.hpp Normal file
View File

@ -0,0 +1,47 @@
#ifndef TCP_CLIENT_HPP
#define TCP_CLIENT_HPP
#include "Defs.hpp"
#include "NetworkMessage.hpp"
#include <string>
#ifdef _MSC_VER
#pragma once
#endif
class TcpClient
{
public:
TcpClient();
TcpClient(const std::string &ip, uint16 port = default_port);
~TcpClient();
const std::string &GetIP();
void SetIP(const std::string &ip);
uint16 GetPort();
void SetPort(uint16 port);
VoidCode Connect(); // this function is used if Initialize was not called
char *ReceiveDataArray();
const NetworkMessage &ReceiveData();
bool SendData(const NetworkMessage &message);
private:
VoidCode Initialize(const std::string &ip, uint16 port = default_port);
std::string ip;
uint16 port = 0;
bool initialized;
#ifdef _MSC_VER
SOCKET socket = INVALID_SOCKET;
struct addrinfo *result = nullptr;
struct addrinfo *ptr = nullptr;
struct addrinfo hints;
#endif
};
#endif