started working on the networking part of the chat client

This commit is contained in:
Kjistóf 2016-11-29 18:24:33 +01:00
parent c6750bbb54
commit 60bb1e6142

35
chat_networking.hpp Normal file
View File

@ -0,0 +1,35 @@
#include <iostream>
#include <functional>
#include <boost/asio.hpp>
#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));
}
};