written a quick, unfinished implementation of message
This commit is contained in:
parent
80cc602317
commit
6cb3cb0c79
35
text_message.cpp
Normal file
35
text_message.cpp
Normal 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
21
text_message.h
Normal 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;
|
||||
};
|
Loading…
Reference in New Issue
Block a user