From 6cb3cb0c79511a42c75ef04c1a6932775dfe88d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Sat, 19 Nov 2016 17:25:39 +0100 Subject: [PATCH] written a quick, unfinished implementation of message --- text_message.cpp | 35 +++++++++++++++++++++++++++++++++++ text_message.h | 21 +++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 text_message.cpp create mode 100644 text_message.h diff --git a/text_message.cpp b/text_message.cpp new file mode 100644 index 0000000..7b74624 --- /dev/null +++ b/text_message.cpp @@ -0,0 +1,35 @@ +#include "text_message.h" + +using namespace boost; + + + +text_message::text_message() {} + + +text_message::text_message(std::string text):_text(text) +{} + + +void text_message::send(boost::asio::ip::tcp::socket& socket) +{ + boost::system::error_code ec; + + + asio::write(socket, asio::buffer(std::to_string(_text.size())), ec); + + asio::write(socket, asio::buffer(":", sizeof(char)), ec); + + asio::write(socket, asio::buffer(_text), ec); + + if (ec) + throw std::runtime_error("Networking error: " + ec.message()); +} + + +void text_message::receive(boost::asio::ip::tcp::socket& socket) +{} + + +text_message::~text_message() +{} diff --git a/text_message.h b/text_message.h new file mode 100644 index 0000000..56389f3 --- /dev/null +++ b/text_message.h @@ -0,0 +1,21 @@ +#pragma once + +#include "message.h" +#include + + + +class text_message : public message +{ +private: + std::string _text; + +public: + text_message(); + text_message(std::string); + + virtual void send(boost::asio::ip::tcp::socket&) override; + virtual void receive(boost::asio::ip::tcp::socket&) override; + + virtual ~text_message() override; +};