summaryrefslogblamecommitdiffstats
path: root/include/network/NetworkClient.hpp
blob: 22b1b2220c4c71f34319604f7c9946320b723da5 (plain) (tree)
1
2
3
4
5
6
7
8
9

            
                 
                
                

                              
 
                     









                                                       
       

                                                                                                  
 


                                                        
#pragma once

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

#include <network/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;
	bool &isRunning;
	ConnectionState state;
	void NetworkLoop();
public:
	NetworkClient(std::string address, unsigned short port, std::string username, bool &quit);
	~NetworkClient();

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