boost-asio

Simple server using Boost.Asio throws an exception

自古美人都是妖i 提交于 2021-01-27 17:08:08
问题 I am trying to write a simple server using Boost.Asio library. I want my server to receive a message from the client and print that message on the console. Here is the code of my server program: #include <iostream> #include <string> #include <memory> #include <boost/asio.hpp> using namespace boost::asio; using namespace boost::system; using boost::asio::ip::tcp; class Session : public std::enable_shared_from_this<Session> { public: Session(tcp::socket socket); void start(); private: tcp:

C++ Linux Google Protobuf + boost::asio Cannot Parse

大兔子大兔子 提交于 2021-01-27 12:14:31
问题 I am trying to send a Google Protobuf message over a boost::asio socket via TCP. I recognize that TCP is a streaming protocol and thus I am performing length-prefixing on the messages before they go through the socket. I have the code working, but it only appears to work some of the time, even though I'm repeating the same calls and not changing the environment. On occasion I will receive the following error: [libprotobuf ERROR google/protobuf/message_lite.cc:123] Can't parse message of type

read from keyboard using boost async_read and posix::stream_descriptor

半世苍凉 提交于 2020-12-06 13:01:19
问题 I am trying to capture single keyboard inputs in a non blocking way inside a while loop using boost asio async_read. The handler is expected to display the read characters. My code: #include <boost/asio/io_service.hpp> #include <boost/asio/posix/stream_descriptor.hpp> #include <boost/asio/read.hpp> #include <boost/system/error_code.hpp> #include <iostream> #include <unistd.h> #include <termios.h> using namespace boost::asio; void read_handler(const boost::system::error_code&, std::size_t) {