started working on the networking part of the chat client
This commit is contained in:
parent
c6750bbb54
commit
60bb1e6142
35
chat_networking.hpp
Normal file
35
chat_networking.hpp
Normal 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));
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user