Added initialization, data type defenitons and started with TcpClient
This commit is contained in:
17
include/Config.hpp
Normal file
17
include/Config.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef CONFIG_HPP
|
||||
#define CONFIG_HPP
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
struct Config
|
||||
{
|
||||
static void SetUsingConsole(bool value);
|
||||
static bool GetUsingConsole();
|
||||
|
||||
private:
|
||||
static bool using_console;
|
||||
};
|
||||
|
||||
#endif
|
||||
188
include/Defs.hpp
Normal file
188
include/Defs.hpp
Normal file
@ -0,0 +1,188 @@
|
||||
#ifndef DEFS_HPP
|
||||
#define DEFS_HPP
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define _WINSOCKAPI_
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
|
||||
WSADATA wsa_data;
|
||||
|
||||
typedef signed char int8, sbyte;
|
||||
typedef unsigned char uint8, byte;
|
||||
typedef signed short int16;
|
||||
typedef unsigned short uint16;
|
||||
typedef signed int int32;
|
||||
typedef unsigned int uint32;
|
||||
typedef signed __int64 int64;
|
||||
typedef unsigned __int64 uint64;
|
||||
|
||||
#ifdef _WIN64
|
||||
typedef signed __int64 int_ptr;
|
||||
typedef unsigned __int64 uint_ptr;
|
||||
#else
|
||||
typedef signed long int_ptr;
|
||||
typedef unsigned long uint_ptr;
|
||||
#endif // win64
|
||||
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
typedef signed char int8, sbyte;
|
||||
typedef unsigned char uint8, byte;
|
||||
typedef signed short int16;
|
||||
typedef unsigned short uint16;
|
||||
typedef signed int int32;
|
||||
typedef unsigned int uint32;
|
||||
|
||||
#ifdef _WIN64
|
||||
typedef signed long long int_ptr, int64;
|
||||
typedef unsigned long long uint_ptr, uint64;
|
||||
#else
|
||||
typedef signed long int_ptr;
|
||||
typedef unsigned long uint_ptr;
|
||||
|
||||
#ifdef __LP64__
|
||||
typedef signed long int64;
|
||||
typedef unsigned long uint64;
|
||||
#else
|
||||
typedef signed long long int64;
|
||||
typedef unsigned long long uint64;
|
||||
#endif // __LP64__
|
||||
|
||||
#endif // win64
|
||||
|
||||
#elif defined(__DECCXX)
|
||||
|
||||
typedef signed char int8, sbyte;
|
||||
typedef unsigned char uint8, byte;
|
||||
typedef signed short int16;
|
||||
typedef unsigned short uint16;
|
||||
typedef signed int int32;
|
||||
typedef unsigned int uint32;
|
||||
typedef signed __int64 int64;
|
||||
typedef unsigned __int64 uint64;
|
||||
|
||||
#ifdef __VMS
|
||||
#ifdef __32BITS
|
||||
typedef signed long int_ptr;
|
||||
typedef unsigned long uint_ptr;
|
||||
#else
|
||||
typedef signed __int64 int_ptr;
|
||||
typedef unsigned __int64 uint_ptr;
|
||||
#endif // __32BITS
|
||||
#else
|
||||
typedef signed long int_ptr;
|
||||
typedef unsigned long uint_ptr
|
||||
#endif // __VMS
|
||||
|
||||
#elif defined(__HP_aCC)
|
||||
|
||||
typedef signed char int8, sbyte;
|
||||
typedef unsigned char uint8, byte;
|
||||
typedef signed short int16;
|
||||
typedef unsigned short uint16;
|
||||
typedef signed int int32;
|
||||
typedef unsigned int uint32;
|
||||
typedef signed long int_ptr;
|
||||
typedef unsigned long uint_ptr;
|
||||
|
||||
#ifdef __LP64__
|
||||
typedef signed long int64;
|
||||
typedef unsigned long uint64;
|
||||
#else
|
||||
typedef signed long long int64;
|
||||
typedef unsigned long long uint64;
|
||||
#endif // __LP64__
|
||||
|
||||
#elif defined(__SUNPRO_CC)
|
||||
|
||||
typedef signed char int8, sbyte;
|
||||
typedef unsigned char uint8, byte;
|
||||
typedef signed short int16;
|
||||
typedef unsigned short uint16;
|
||||
typedef signed int int32;
|
||||
typedef unsigned int uint32;
|
||||
typedef signed long int_ptr;
|
||||
typedef unsigned long uint_otr
|
||||
|
||||
#ifdef __sparcv9
|
||||
typedef signed long int64;
|
||||
typedef unsigned long uint64;
|
||||
#else
|
||||
typedef signed long long int64;
|
||||
typedef unsigned long long uint64;
|
||||
#endif // __sparcv9
|
||||
|
||||
#elif defined(__IBMCPP__)
|
||||
|
||||
typedef signed char int8, sbyte;
|
||||
typedef unsigned char uint8, byte;
|
||||
typedef signed short int16;
|
||||
typedef unsigned short uint16;
|
||||
typedef signed int int32;
|
||||
typedef unsigned int uint32;
|
||||
typedef signed long int_ptr;
|
||||
typedef unsigned long uint_ptr;
|
||||
|
||||
#ifdef __64BIT__
|
||||
typedef signed long int64;
|
||||
typedef unsigned long uint64;
|
||||
#else
|
||||
typedef signed long long int64;
|
||||
typedef unsigned long long uint64;
|
||||
#endif // __64BIT__
|
||||
|
||||
#elif defined(__sgi)
|
||||
|
||||
typedef signed char int8, sbyte;
|
||||
typedef unsigned char uint8, byte;
|
||||
typedef signed short int16;
|
||||
typedef unsigned short uint16;
|
||||
typedef signed int int32;
|
||||
typedef unsigned int uint32;
|
||||
typedef signed long int_ptr;
|
||||
typedef unsigned long uint_ptr;
|
||||
|
||||
#if _MIPS_SZLONG == 64
|
||||
typedef signed long int64;
|
||||
typedef unsigned long uint64;
|
||||
#else
|
||||
typedef signed long long int64;
|
||||
typedef unsigned long long uint64;
|
||||
#endif // _MIPS_SZLONG
|
||||
|
||||
#elif defined(_DIAB_TOOL)
|
||||
|
||||
typedef signed char int8, sbyte;
|
||||
typedef unsigned char uint8, byte;
|
||||
typedef signed short int16;
|
||||
typedef unsigned short uint16;
|
||||
typedef signed int in32;
|
||||
typedef unsigned int uint32;
|
||||
typedef signed long int_ptr;
|
||||
typedef unsigned long uint_ptr;
|
||||
typedef signed long long int64;
|
||||
typedef unsigned long long uint64;
|
||||
|
||||
#endif // compiler data type defenitions
|
||||
|
||||
const uint16 default_port = 60250;
|
||||
|
||||
enum VoidCode
|
||||
{
|
||||
VOID_SUCCESS,
|
||||
VOID_WSA_INIT_FAILED,
|
||||
VOID_TCP_INIT_FAILED,
|
||||
VOID_INVALID_IP_ADDRESS,
|
||||
VOID_INVALID_PORT,
|
||||
VOID_COULDNT_CONNECT,
|
||||
};
|
||||
|
||||
#endif // DEFS_HPP
|
||||
12
include/Init.hpp
Normal file
12
include/Init.hpp
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef INIT_HPP
|
||||
#define INIT_HPP
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "Defs.hpp"
|
||||
|
||||
VoidCode initialize();
|
||||
|
||||
#endif
|
||||
16
include/NetworkMessage.hpp
Normal file
16
include/NetworkMessage.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef NETWORK_MESSAGE_HPP
|
||||
#define NETWORK_MESSAGE_HPP
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
class NetworkMessage
|
||||
{
|
||||
public:
|
||||
NetworkMessage();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
47
include/TcpClient.hpp
Normal file
47
include/TcpClient.hpp
Normal 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
|
||||
14
include/Utility.hpp
Normal file
14
include/Utility.hpp
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef UTILITY_HPP
|
||||
#define UTILITY_HPP
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
struct Utility
|
||||
{
|
||||
static void Delete(void *pointer);
|
||||
static void DeleteArray(void *pointer);
|
||||
};
|
||||
|
||||
#endif
|
||||
11
include/VoidNet.hpp
Normal file
11
include/VoidNet.hpp
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef VOID_NET_HPP
|
||||
#define VOID_NET_HPP
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <Defs.hpp>
|
||||
#include <Init.hpp>
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user