From 60bb1e6142b413adef68ce9575039b64b3fac80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Tue, 29 Nov 2016 18:24:33 +0100 Subject: [PATCH] started working on the networking part of the chat client --- chat_networking.hpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 chat_networking.hpp diff --git a/chat_networking.hpp b/chat_networking.hpp new file mode 100644 index 0000000..7f36689 --- /dev/null +++ b/chat_networking.hpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include "chat_messages.hpp" + + + +class client_network_manager +{ + using namespace boost; + using boost::asio::ip::tcp; + +private: + asio::io_service& _ios; + tcp::socket _socket; + asio::streambuf _sb; + std::istream _is{&sb}; + std::ostream _os{&sb}; + + void handshake(boost::system::error_code ec, size_t) + { + if (ec) + throw std::runtime_error("Networking error: " + ec.message()); + + // TODO: do handshake & read-loop + } + +public: + client_network_manager(asio::io_service& ioservice, tcp::resolver::query query) + :_ios(ioservice) + { + asio::async_connect(_socket,tcp::resolver().resolve(query), + std::bind(&client_network_manager::handshake, this)); + } +}; \ No newline at end of file