boost-asio

How To Apply This Boost ASIO Example To My Application

此生再无相见时 提交于 2019-12-07 07:20:58
问题 I've been reading a lot of ASIO examples, but I'm still sort of confused on how to use them in my application. Basically, my server side needs to accept more than 100 connections (clients), this part is done by using a pool of threads (usually, 2~4 threads for each CPU core). For simplicity, let's just assume there is only one connection. For simplicity, I would also like to copy the example from: http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/example/nonblocking/third_party_lib.cpp

How to specify a specific NIC to be used in an application written in c++ (boost asio)

心不动则不痛 提交于 2019-12-07 06:44:51
问题 I have a machine connected to multiple independent networks, each on a different NIC (Network Interface Card). The machine runs Windows 7. I run an application on the machine which needs to connect to a specific IP through a specific NIC, using TCP. The application uses c++11 and boost asio (1.53.0) for networking, and the source can be changed. What are the different reasonable ways to solve this problem (specify endpoint IP and NIC) in a Windows environment? The current solution assigns the

boost::asio async handlers invoked without error after cancellation

一个人想着一个人 提交于 2019-12-07 06:09:19
问题 My code uses boost::asio and io_service in a single thread to perform various socket operations. All operations are asynchronous and every handler depends on the boost::system::error_code (particularly boost::asio::error::operation_aborted ) to determine the result of the operation. It's been working perfectly well until I changed the logic to make several concurrent connections and pick the fastest one. That is, when the first async_read_some handler fires, I cancel other sockets (shutdown,

Reading Protobuf objects using boost::asio::read_async

◇◆丶佛笑我妖孽 提交于 2019-12-07 04:59:06
问题 I am writing an application using Boost asio in which the client and the server exchange messages that are serialized using google proto-buffers. I do not know what is the size of the serialized message being sent on over the network. It seems that the proto-buf objects do not have any delimiter. Here are the contents of the .proto file. package tutorial; message Person { required string name = 1; required int32 id = 2; optional string email = 3; } Here is how I am writing from the server

Should I be seeing significant differences between std::bind and boost::bind?

不羁岁月 提交于 2019-12-07 03:56:54
问题 I'm exploring the support for C++11 on the g++-4.7 (Ubuntu/Linaro 4.7.3-2ubuntu~12.04, to be specific) and I seem to be finding differences. In particular, if I comment out #include <boost/bind.hpp> and systematically replace occurrences of boost::bind with std::bind in the Boost ASIO async client example (taken from http://www.boost.org/doc/libs/1_45_0/doc/html/boost_asio/example/http/client/async_client.cpp), the program no longer compiles. Any explanation for this? 回答1: #include

Interrupt boost::asio synchronous read?

你。 提交于 2019-12-07 03:29:05
问题 I'm using asio synchronous sockets to read data over TCP from a background thread. This is encapsulated in a "server" class. However, I want the thread to exit when the destructor of this class is called. The problem is that a call to any of the read functions does block, so the thread cannot be easily terminated. In Win32 there is an API for that: WaitForMultipleObjects which would do exactly what I want. How would I achieve a similar effect with boost? 回答1: In our application, we set the

Boost ASIO socket read N bytes not more not less and wait until they come or timeout exception?

纵饮孤独 提交于 2019-12-07 02:54:47
问题 Creating a simple TCP server based on examples but still do not get how to create a socket that would read some amount of bytes and if there will not be enough would wait. I need this to be NOT asynchronous operation. #include <iostream> #include <boost/asio.hpp> #ifdef _WIN32 #include "Windows.h" #endif using namespace boost::asio::ip; using namespace std; int main(){ int m_nPort = 12345; boost::asio::io_service io_service; tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v4(), m_nPort)

What's wrong with this boost::asio and boost::coroutine usage pattern?

倖福魔咒の 提交于 2019-12-07 02:42:30
问题 In this question I described boost::asio and boost::coroutine usage pattern which causes random crashes of my application and I published extract from my code and valgrind and GDB output. In order to investigate the problem further I created smaller proof of concept application which applies the same pattern. I saw that the same problem arises in the smaller program which source I publish here. The code starts a few threads and creates a connection pool with a few dummy connections (user

Boost asio - multiple client connections to different servers

谁说胖子不能爱 提交于 2019-12-07 01:55:41
问题 I am trying to evaluate using async boost udp/tcp socket operations vs synchronous for my application. I have been trying to find an example that is similar to my design but did not find anything which led me to believe I might be trying to fit async ops into my design even though it is not the right path. I want to connect to multiple (read: between 1-10) servers and communicate with them using different protocols; I have 4-5 threads which are producing data that needs to be communicated to

boost:asio IPv4 address and UDP comms

自闭症网瘾萝莉.ら 提交于 2019-12-07 00:36:11
问题 Problem Solved - See bottom for solution notes I'm trying to build a simple app to test an ethernet-capable microcontroller. All I want to do is send and receive small UDP packets. The code is using boost::asio for the networking, and is incredibly simple. For debugging I moved all the intialisation out of the constructors so I could check each step. Here's the body of my stuff: boost::system::error_code myError; boost::asio::ip::address_v4 targetIP; targetIP.from_string("10.1.1.75", myError)