summaryrefslogtreecommitdiffstats
path: root/src/NetworkClient.hpp
blob: 83db5177d0e07c1a24e7cfbf067dad40b0e775be (plain) (blame)
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
#pragma once

#include <thread>
#include <queue>
#include <mutex>

#include "Network.hpp"

class NetworkClient {
	Network network;
	std::thread networkThread;
	std::mutex toSendMutex;
	std::mutex toReceiveMutex;
	std::queue <std::shared_ptr<Packet>> toSend;
	std::queue <std::shared_ptr<Packet>> toReceive;
	bool isActive=true;
	ConnectionState state;
	void NetworkLoop();
public:
	NetworkClient(std::string address, unsigned short port, std::string username);
	~NetworkClient();

	std::shared_ptr <Packet> ReceivePacket();
	void SendPacket(std::shared_ptr<Packet> packet);
};