#ifndef REMOTE_SERVER_H #define REMOTE_SERVER_H #include <Util.h> #include <array> #include <chrono> #include <cstdint> #include <memory> #include <shared_mutex> #include <thread> #include <unordered_map> #include <wx/event.h> #include <wx/evtloop.h> #include <wx/socket.h> #include <wx/wx.h> using highClock_t = std::chrono::time_point<std::chrono::high_resolution_clock>; struct TranClient { std::shared_ptr<wxSocketBase> wxSock; MutBuffer buffer; int64_t onlineTime; highClock_t lastRecvTime; }; class RemoteServer : public wxEvtHandler { public: RemoteServer(); public: bool Init(const wxString& ip, unsigned short port); int Run(); private: void OnServerEvent(wxSocketEvent& event); void thClientThread(const std::shared_ptr<wxSocketBase>& wxSock, const wxString& id); private: wxWindowID serverId_; std::shared_mutex clientsMutex_; std::unique_ptr<wxSocketServer> server_; std::unordered_map<wxString, std::thread> threads_; std::unordered_map<wxString, std::shared_ptr<TranClient>> clients_; }; #endif // REMOTE_SERVER_H