asio

Boost.Asio C++ 网络编程之一:什么是Boost.Asio?

纵饮孤独 提交于 2020-01-25 01:55:52
引言 文章的内容是翻译 《Boost.Asio C++ Network Programming》这本书。 编译IDE环境是 vs2017 什么是Boost.Asio? 简单来说,Boost.Asio是一个跨平台的、主要用于网络和其他一些底层输入/输出编程的C++库。 关于网络处理已经有很多解决方案,但是Boost.Asio是目前为止最优的方案。它在2005年就被包含进Boost,然后被大量Boost的用户测试并使用在许多项目中,比如:Remobo(http://www.remobo.com),可以让你创建你自己的即时私有网络(IPN);libtorrent(http://www.rasterbar.com/products/libtorrent)),一个用于实现比特流客户端的库;PokerTH (http://www.pokerth.net),一个支持LAN和互联网对战的纸牌游戏。 Boost.Asio在网络通信、COM串行端口和文件上成功地抽象了输入输出的概念。你可以基于这些进行同步或者异步的输入输出编程。 read ( stream , buffer [ , extra options ] ) async_read ( stream , buffer [ , extra options ] , handler ) write ( stream , buffer [ ,

Async sending and receiving custom data packets with boost?

不羁的心 提交于 2019-12-23 16:53:32
问题 I am trying to asynchronously send and receive custom data packets with boost and I have some questions, based on my current implementation: tcpclient.cpp #include "tcpclient.h" #include <boost/chrono.hpp> #include "../utils/logger.h" tcpclient::tcpclient(std::string host, int port) : _endpoint(boost::asio::ip::address::from_string(host), port), _socket(_ioservice) { logger::log_info("Initiating client ..."); } void tcpclient::start() { connect(); _ioservice.run(); } void tcpclient::connect()

ASIO UDP: class std::allocator<void> has no member named ‘construct’

三世轮回 提交于 2019-12-23 02:13:32
问题 I have followed this example to set up an asynchronous UDP receive. But it fails on compilation: g++ -Wall -Wconversion -Wfatal-errors -Wextra -std=c++11 test1.cpp Error message: In file included from /usr/include/c++/5/ext/alloc_traits.h:36:0, from /usr/include/c++/5/bits/basic_string.h:40, from /usr/include/c++/5/string:52, from /usr/include/c++/5/stdexcept:39, from /usr/include/c++/5/array:38, from /usr/include/c++/5/tuple:39, from /usr/include/c++/5/functional:55, from /usr/include/c++/5

如何在动态链接库dll/so中导出自定义的模板类template class

爱⌒轻易说出口 提交于 2019-12-20 08:32:07
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 本文首发于个人博客 https://kezunlin.me/post/4ec4ae49/ ,欢迎阅读最新内容! how to implement a template class with c++ and export in dll/so <!--more--> Guide questions 模板类必须在header中实现,而不能在cpp中实现,否则作为dll调用进行链接的时候回出错。 common solutions(Recommend) implement template functions in header. ThreadPool.h class SHARED_EXPORT ThreadPool { public: static ThreadPool* Instance(size_t max_thread_pool_size); ~ThreadPool(); // Add new work item to the pool. template<class F> inline void Enqueue(F f) { io_service_.post(f);//sync, return immediately } void Free(); private: static std::shared_ptr

How to calculate FFT using NAudio in realtime (ASIO out)

折月煮酒 提交于 2019-12-19 03:31:08
问题 I am programming clone of guitar (violin) Hero as a final project for this school year. The idea is to take input from my electric violin, analyse it via FFT, do some logic and drawing and output it through speakers. Perhaps some steps in parallel threads. I already have Asio low latency input-output implemented but I am having a great problem implementing realtime FFT. This is a code that sets up asioOut along with sampleAggregator. Sample aggregator should store samples that are added each

C++ Boost ASIO: initializing io_context inside class:

走远了吗. 提交于 2019-12-13 01:24:41
问题 I am following Boost UDP multicast sender tutorial here . I modify it to make a class as follow: #define _CRT_SECURE_NO_WARNINGS #include <ctime> #include <iostream> #include <string> #include <boost/array.hpp> #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> #include <boost/asio.hpp> #include <boost/lexical_cast.hpp> #include <boost/thread.hpp> using boost::asio::ip::udp; using std::cout; using std::cin; using std::endl; class sender { private: boost::asio::io_context io_context;

Writing binary mangles data

我们两清 提交于 2019-12-12 12:41:47
问题 In my application, I record audio data from an ASIO driver: void newData(void *buffer, int length) where buffer is the buffer pointer and length is the number of samples in that buffer. In my case, I know that the samples are 4-byte integers and the buffer contains 1024 samples every run. Now, I save these samples in two ways: little-endian binary (to be later used as a WAV file) and a text file. The text file saving words good, I get the numbers and they correspond to the samples form the

Wondering why I couldn't just capture the reference of asio::handler_type for the coroutine

爷,独闯天下 提交于 2019-12-12 03:39:54
问题 I'm playing with the asio using coroutine, and would like to test how an async function can be called. I have the following code: void async_foo(boost::asio::io_service& io_service, boost::asio::yield_context& yield) { using handler_type = boost::asio::handler_type<decltype(yield), void()>::type; handler_type handler(std::forward<handler_type>(yield)); boost::asio::async_result<decltype(handler)> result(handler); auto timer(std::make_shared<boost::asio::deadline_timer>(io_service, boost:

ASIO UDP: class std::allocator<void> has no member named ‘construct’

亡梦爱人 提交于 2019-12-08 15:16:30
I have followed this example to set up an asynchronous UDP receive. But it fails on compilation: g++ -Wall -Wconversion -Wfatal-errors -Wextra -std=c++11 test1.cpp Error message: In file included from /usr/include/c++/5/ext/alloc_traits.h:36:0, from /usr/include/c++/5/bits/basic_string.h:40, from /usr/include/c++/5/string:52, from /usr/include/c++/5/stdexcept:39, from /usr/include/c++/5/array:38, from /usr/include/c++/5/tuple:39, from /usr/include/c++/5/functional:55, from /usr/include/c++/5/thread:39, from test1.cpp:1: /usr/include/c++/5/bits/alloc_traits.h: In instantiation of ‘static void