mirror of
https://github.com/maxDcb/C2TeamServer
synced 2026-06-06 16:14:27 +00:00
67 lines
1007 B
C++
67 lines
1007 B
C++
#pragma once
|
|
|
|
#include <fstream>
|
|
#include <memory>
|
|
#include <chrono>
|
|
#include <random>
|
|
#include <vector>
|
|
#include <thread>
|
|
|
|
#include <boost/asio.hpp>
|
|
#include <boost/bind/bind.hpp>
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
namespace SocketHandler
|
|
{
|
|
|
|
class Server
|
|
{
|
|
public:
|
|
Server(int port);
|
|
~Server();
|
|
|
|
bool sendData(std::string& data);
|
|
bool receive(std::string& data);
|
|
|
|
private:
|
|
void reset();
|
|
void initServer();
|
|
void creatServerTcp(int port);
|
|
|
|
bool m_initDone;
|
|
int m_port;
|
|
|
|
std::thread* threadInit;
|
|
|
|
boost::asio::io_service m_ioService;
|
|
boost::asio::ip::tcp::socket* m_socketTcp;
|
|
boost::system::error_code m_error;
|
|
};
|
|
|
|
|
|
|
|
class Client
|
|
{
|
|
public:
|
|
Client(std::string& ip, int port);
|
|
~Client();
|
|
|
|
bool sendData(std::string& data);
|
|
bool receive(std::string& data);
|
|
|
|
private:
|
|
void reset();
|
|
void creatClientTcp(int port, std::string& ip);
|
|
|
|
std::string m_ipServer;
|
|
int m_port;
|
|
|
|
boost::asio::io_service m_ioService;
|
|
boost::asio::ip::tcp::socket* m_socketTcp;
|
|
boost::system::error_code m_error;
|
|
};
|
|
|
|
}
|
|
|
|
|