1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- /*
- * NetworkClient.cpp, part of VCMI engine
- *
- * Authors: listed in file AUTHORS in main folder
- *
- * License: GNU General Public License v2.0 or later
- * Full text of license available in license.txt file, in main folder
- *
- */
- #include "StdInc.h"
- #include "NetworkClient.h"
- #include "NetworkConnection.h"
- VCMI_LIB_NAMESPACE_BEGIN
- NetworkClient::NetworkClient()
- : io(new NetworkService)
- , socket(new NetworkSocket(*io))
- // , timer(new NetworkTimer(*io))
- {
- }
- void NetworkClient::start(const std::string & host, uint16_t port)
- {
- boost::asio::ip::tcp::resolver resolver(*io);
- auto endpoints = resolver.resolve(host, std::to_string(port));
- boost::asio::async_connect(*socket, endpoints, std::bind(&NetworkClient::onConnected, this, _1));
- }
- void NetworkClient::onConnected(const boost::system::error_code & ec)
- {
- connection = std::make_shared<NetworkConnection>(socket);
- connection->start();
- }
- void NetworkClient::run()
- {
- io->run();
- }
- void NetworkClient::sendPacket(const std::vector<uint8_t> & message)
- {
- connection->sendPacket(message);
- }
- VCMI_LIB_NAMESPACE_END
|