From 8c78e28b7ff3fbc7f6a84b6adc417e1ce6ca13a3 Mon Sep 17 00:00:00 2001 From: auth Date: Thu, 2 Jul 2020 14:20:45 +0200 Subject: Added client timeout. Added json imports for pe images. Added wrapper to support streaming strings. --- client/src/client/client.h | 12 ++++++++++++ client/src/client/packet.h | 2 +- client/src/main.cpp | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) (limited to 'client/src') diff --git a/client/src/client/client.h b/client/src/client/client.h index 2e4374f..9bc0eb2 100644 --- a/client/src/client/client.h +++ b/client/src/client/client.h @@ -43,6 +43,18 @@ class client { int read_stream(std::vector& out); int stream(std::vector& data); + int stream(std::string &str) { + std::vector vec(str.begin(), str.end()); + return stream(vec); + } + + int read_stream(std::string &str) { + std::vector out; + int ret = read_stream(out); + str.assign(out.begin(), out.end()); + return ret; + } + int get_socket() { return m_socket; } operator bool() const { return m_active; } diff --git a/client/src/client/packet.h b/client/src/client/packet.h index 39b17de..992bee7 100644 --- a/client/src/client/packet.h +++ b/client/src/client/packet.h @@ -5,7 +5,7 @@ namespace tcp { constexpr size_t session_id_len = 10; -constexpr size_t message_len = 1024; +constexpr size_t message_len = 512; enum packet_type : int { write = 0, read }; diff --git a/client/src/main.cpp b/client/src/main.cpp index c932b44..61b97d5 100644 --- a/client/src/main.cpp +++ b/client/src/main.cpp @@ -28,7 +28,19 @@ int main(int argc, char* argv[]) { return; } + if (message == "timedout") { + io::logger->warn("connection timeout."); + client.shutdown(); + } + io::logger->info("{}:{}->{}", packet.id, packet.session_id, message); + + std::string imports; + client.read_stream(imports); + + auto json = nlohmann::json::parse(imports); + std::ofstream o("o"); + o << std::setw(4) << json; }); while (client) { -- cgit v1.2.3