boost-asio

Boost asio - separate different chunks of data

孤人 提交于 2020-01-11 12:25:51
问题 Imagine we create simple client-server app to send files from client to server. We use boost asio. Server starts listening. Client connects to the server. Client send filename and file content. But server receive just a stream of bytes. How server detect end of filename and start of file content? First idea I have is to use special delimiter. Client writes into the socket filename, then delimiter, then file content. Server uses 'read_until' to receive filename and 'read' to read file content.

Boost asio - separate different chunks of data

巧了我就是萌 提交于 2020-01-11 12:24:54
问题 Imagine we create simple client-server app to send files from client to server. We use boost asio. Server starts listening. Client connects to the server. Client send filename and file content. But server receive just a stream of bytes. How server detect end of filename and start of file content? First idea I have is to use special delimiter. Client writes into the socket filename, then delimiter, then file content. Server uses 'read_until' to receive filename and 'read' to read file content.

boost asio post not working , io_service::run exits right after post

*爱你&永不变心* 提交于 2020-01-11 11:09:08
问题 I am trying to mix boost signals with asio to do a dispatch based handler invocation. when the post method is invoked from a thread the io_service::run exits immediately, the callback handled to post is never invoked, callback is a C++11 lambda routine. I am pasting the code for more analysis. #include<iostream> #include<thread> #include<boost/signals2/signal.hpp> #include<boost/asio.hpp> static boost::asio::io_service svc; static boost::signals2::signal<void(std::string)> textEntered; static

boost asio post not working , io_service::run exits right after post

主宰稳场 提交于 2020-01-11 11:08:12
问题 I am trying to mix boost signals with asio to do a dispatch based handler invocation. when the post method is invoked from a thread the io_service::run exits immediately, the callback handled to post is never invoked, callback is a C++11 lambda routine. I am pasting the code for more analysis. #include<iostream> #include<thread> #include<boost/signals2/signal.hpp> #include<boost/asio.hpp> static boost::asio::io_service svc; static boost::signals2::signal<void(std::string)> textEntered; static

Clear input data from serial port in boost::asio

余生颓废 提交于 2020-01-11 06:43:10
问题 I'm writing a C++ program for communicating with a Arduino over a serial port using boost::asio. After establishing the connection the Arduino resets itself. However the input buffer of the C++ program still contains old data sent from the Arduino. Since I have no use for this data I'd like clear the input buffer. How can I accomplish that using boost::asio? My code currently looks like this: #include <boost/asio.hpp> #include <vector> #include <iostream> using namespace std; using namespace

C++: Boost.Asio: Start SSL Server session in a new thread

一世执手 提交于 2020-01-10 03:16:04
问题 I wrote a pair of server/client programs based on this example for the server and I'm done of all communication protocols. The server is supposed to receive multiple connections from multiple connections from multiple client, so I want to separate the sessions from each other, and I'm hoping I could do that with std::thread . This looks to be easy, but I don't know how to do it at all. All examples online seem to show how to run a function in parallel, but it doesn't seem to show how to

How to check if socket is closed in Boost.Asio?

匆匆过客 提交于 2020-01-09 11:15:05
问题 What is the easiest way to check if a socket was closed on the remote side of the connection? socket::is_open() returns true even if it is closed on the remote side (I'm using boost::asio::ip::tcp::socket ). I could try to read from the stream and see if it succeeds, but I'd have to change the logic of my program to make it work this way (I do not want data to be extracted from the stream at the point of the check). 回答1: If the connection has been cleanly closed by the peer you should get an

How to check if socket is closed in Boost.Asio?

半腔热情 提交于 2020-01-09 11:13:10
问题 What is the easiest way to check if a socket was closed on the remote side of the connection? socket::is_open() returns true even if it is closed on the remote side (I'm using boost::asio::ip::tcp::socket ). I could try to read from the stream and see if it succeeds, but I'd have to change the logic of my program to make it work this way (I do not want data to be extracted from the stream at the point of the check). 回答1: If the connection has been cleanly closed by the peer you should get an

ASIO async_read doesn't work while async_read_until works on server

眉间皱痕 提交于 2020-01-06 20:19:21
问题 Observation I built a demo application according to this server example using ASIO after I used C++11 std to replace everything originally in boost . The server can show that class member tcp_session::start() is called only after the client connects which is good indication that the server accepts the connection from the client. However, I saw nothing received by handle_read while the clients sends a lot of data. I got some std::cout in handle_read and stop. I put the timeout to be 6 seconds

ASIO async_read doesn't work while async_read_until works on server

无人久伴 提交于 2020-01-06 20:16:08
问题 Observation I built a demo application according to this server example using ASIO after I used C++11 std to replace everything originally in boost . The server can show that class member tcp_session::start() is called only after the client connects which is good indication that the server accepts the connection from the client. However, I saw nothing received by handle_read while the clients sends a lot of data. I got some std::cout in handle_read and stop. I put the timeout to be 6 seconds