written a quick, unfinished implementation of message

This commit is contained in:
Kjistóf 2016-11-19 17:25:39 +01:00
parent 80cc602317
commit 6cb3cb0c79
2 changed files with 56 additions and 0 deletions

35
text_message.cpp Normal file
View File

@ -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()
{}

21
text_message.h Normal file
View File

@ -0,0 +1,21 @@
#pragma once
#include "message.h"
#include <string>
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;
};