zhllxt / asio2 Goto Github PK
View Code? Open in Web Editor NEWHeader only c++ network library, based on asio,support tcp,udp,http,websocket,rpc,ssl,icmp,serial_port,socks5.
License: Boost Software License 1.0
Header only c++ network library, based on asio,support tcp,udp,http,websocket,rpc,ssl,icmp,serial_port,socks5.
License: Boost Software License 1.0
将asio2\example\http\server中的http服务例程编译,当采用debug启动时,在建立websocket连接时将会发生Assertion failed,而采用release时便可以正常运行
Assertion failed: derive.sessions().io().strand().running_in_this_thread(), file D:\Develop\Lib\asio2\asio2\http\component\ws_stream_cp.hpp, line 83
asio2/http/detail/http_parser.h:535
state类型强制转换,主干分支已修改,但是发布的V2.7版本没有合入,查看发布记录存在文件冲突。
commits 7afc2c2
我现在大概在一个电脑里起动大约300个左右的client,数据处理速度要求比较高,所以想问下是在一个io里面处理所有的client回调吗
RT
看代码tcp都是同步发送的,是否可添加异步发送?另外tcp接收到消息的时候,如果不是整个消息包,应用程序还需要自己保存接收的数据,是否可以添加操作告诉回调函数处理了多少字节,还有多少字节没处理,让调用回调的函数自己处理没有使用的数据.
3rd这个目录能弄成手动git引入不,这样我们工程自动clone以后就不会下载那么多用不到的东西了
template
inline void _handle_accept(const error_code & ec, std::shared_ptr<session_t> session_ptr,
condition_wrap condition)
{
set_last_error(ec);
// if the acceptor status is closed,don't call _post_accept again.
if (ec == asio::error::operation_aborted)
{
this->derived()._do_stop(ec);
return;
}
if (!ec)
{
if (this->is_started())
{
session_ptr->counter_ptr_ = this->counter_ptr_;
session_ptr->start(condition);
}
}
this->derived()._post_accept(std::move(condition));
}
这里明显counter_ptr_和start 是session_ptr的protected不能调用吧
刚接触c++,感觉和其他语言不大一样,项目要求VS2015,球球了
Visual Studio 2017 - Windows XP (v141_xp) 编译失败
最近在拜读源码,对于每个tcp连接绑定一个io对象,一个io对象会同时创建一个strand并且只运行于一个线程中,所有tcp异步操作都会在绑定的ioc线程中执行并且使用strand,如果ioc只运行于单线程的情况下应该不存在线程竞争,那为何要使用strand?这里想不明白
是否可以支持http服务在某些路由上面直接将session升级为websocket连接?
如题
qt5.9.8下提示需要c++17,在pro文件中配置了config+=c++17也没有用。在vs2017下可以编译,但智能提示用不了,凡是引用了asio2的都用不了智能提示,编译也有智能提示方面的错误;代码编辑界面上很多函数和变量都飘红。
在运行ws server时候,
server.bind_recv([](auto & session_ptr, std::string_view s){
....
session_ptr->send(std::string("s"), [](std::size_t bytes_sent) {});
}
这里的send不起任何作用,究竟是在哪里进行发送的?
另外一个问题就是好像用不用bind_recv都会接收数据,这是为什么?
我需要一个接口,接口的功能是收到服务端带着证书的response后,客户端可以忽略掉证书,所以前提肯定需要支持https。
所以这个库支持https吗?以及有没有相关功能的接口?
感谢回复
使用Http client请求内网接口,报错400 :
Your browser sent a request that this server could not understand.
Reason: You're speaking plain HTTP to an SSL-enabled server port.
Instead use the HTTPS scheme to access this URL, please.
我的使用方式:
std::string url = "https://192.168.2.3/aaaaaa";
http::web_request req2 = http::make_request(url);
req2.method(http::verb::get);
auto rep2 = asio2::http_client::execute(req2);
以上请求,使用curl或者postman是可以请求到内容的。
在进行TCP数据传输的时候,如果一个client同时向server发数据,server接收的数据就会合并在一起。应该原因就是采用的异步接收方式导致的,那么对于这种情况的话,是采用同步方式来改程序好还是在现有代码下有解决方案?
代码里采用的都是async_read,这里能否改成同步的read呢,我自己试了下不行。
示例代码,创建http服务,相同client(tcp)链路多次请求,第二次服务就收到数据了。使用的异步http服务。
你好:
我在使用可靠UDP的时候,发现一个这样的问题:启动了client和server,然后我直接关闭了client或server,在重新启动一个对应的client或server,发现不会重新连接,而且等待的时间特别长。也就是说当一个client或者server异常崩溃后,收不到对应的断开信号,我试了一下tcp的那个,tcp那个就可以,断开后,直接在启动,会自动连接上。
想问一下udp的可靠传输下,这个问题怎么解决?
Asio 1.14.0 / Boost 1.70中删除了这个函数
boost的更新日志
The previously deprecated get_io_context and get_io_service member functions have now been removed.
rpc client/server 连接建立后
在client端用async_call 调用同一个方法,在server端的接收顺序是随机的还是按client端的调用顺序到达的?
如果client端在同一个线程用async_call 连续多次调用同一个方法,在server端的接收顺序是否按调用顺序到达?
c++20支持协程了,感觉协程是编写复杂异步代码的好方法
rpc server/client 的同步调用call 是不是只能在创建对象的线程调用 ,或者说是不是不能在任意的线程中调用 ?
因为_do_call 里面有个断言
// Unable to invoke synchronization rpc call function in communication thread
ASIO2_ASSERT(false);
ec = asio::error::operation_not_supported;
请教一下 这个同步调用对调用线程有什么要求?
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/external/magic_enum.hpp: In function 'constexpr std::size_t magic_enum::detail::find(std::string_view, char)':
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/external/magic_enum.hpp:237:29: error: call to non-constexpr function 'std::basic_string_view<_CharT, _Traits>::size_type std::basic_string_view<_CharT, _Traits>::find_first_of(_CharT, std::basic_string_view<_CharT, _Traits>::size_type) const [with _CharT = char; _Traits = std::char_traits; std::basic_string_view<_CharT, Traits>::size_type = unsigned int]'
return str.find_first_of(c);
~~~~~~~~~~~~~~~~~^~~
In file included from /home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/server.hpp:33:0,
from /home/chenya/code/dts/./thirdparty/asio2/include/asio2/tcp/tcp_server.hpp:20,
from /home/chenya/code/dts/./thirdparty/asio2/include/asio2/http/ws_server.hpp:20,
from /home/chenya/code/dts/./thirdparty/asio2/include/asio2/websocket/ws_server.hpp:11,
from /home/chenya/code/dts/src/server/ws_sdk.h:11,
from /home/chenya/code/dts/src/main.cpp:3:
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp: At global scope:
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp:48:56: error: template argument 1 is invalid
std::declval<std::decay_t>()->io_context()), void>> : std::true_type {};
^
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp:48:66: error: template argument 2 is invalid
std::declval<std::decay_t>()->~io_context()), void>> : std::true_type {};
^~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp:55:55: error: template argument 1 is invalid
std::declval<std::decay_t>().io_context()), void>> : std::true_type {};
^
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp:55:65: error: template argument 2 is invalid
std::declval<std::decay_t>().~io_context()), void>> : std::true_type {};
^~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp:64:67: error: template argument 1 is invalid
(std::declval<std::decay_t>())->executor_work_guard()), void>> : std::true_type {};
^
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp:64:77: error: template argument 2 is invalid
(std::declval<std::decay_t>())->~executor_work_guard()), void>> : std::true_type {};
^~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp:71:66: error: template argument 1 is invalid
(std::declval<std::decay_t>()).executor_work_guard()), void>> : std::true_type {};
^
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp:71:76: error: template argument 2 is invalid
(std::declval<std::decay_t>()).~executor_work_guard()), void>> : std::true_type {};
^~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp:75:2: error: static assertion failed
static_assert(is_io_context_pointer<asio::io_context* >::value);
^~~~~~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp:76:2: error: static assertion failed
static_assert(is_io_context_pointer<asio::io_context*& >::value);
^~~~~~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp:77:2: error: static assertion failed
static_assert(is_io_context_pointerasio::io_context*&&::value);
^~~~~~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp:78:2: error: static assertion failed
static_assert(is_io_context_pointer<std::shared_ptrasio::io_context >::value);
^~~~~~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp:79:2: error: static assertion failed
static_assert(is_io_context_pointer<std::shared_ptrasio::io_context& >::value);
^~~~~~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp:80:2: error: static assertion failed
static_assert(is_io_context_pointer<std::shared_ptrasio::io_context&&>::value);
^~~~~~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp:81:2: error: static assertion failed
static_assert(is_io_context_pointer<std::shared_ptrasio::io_contextconst&>::value);
^~~~~~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp:82:2: error: static assertion failed
static_assert(is_io_context_object<asio::io_context >::value);
^~~~~~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp:83:2: error: static assertion failed
static_assert(is_io_context_object<asio::io_context& >::value);
^~~~~~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/base/iopool.hpp:84:2: error: static assertion failed
static_assert(is_io_context_objectasio::io_context&&::value);
^~~~~~~~~~~~~
In file included from /home/chenya/code/dts/./thirdparty/asio2/include/asio2/http/impl/ws_send_op.hpp:29:0,
from /home/chenya/code/dts/./thirdparty/asio2/include/asio2/http/ws_session.hpp:22,
from /home/chenya/code/dts/./thirdparty/asio2/include/asio2/http/ws_server.hpp:21,
from /home/chenya/code/dts/./thirdparty/asio2/include/asio2/websocket/ws_server.hpp:11,
from /home/chenya/code/dts/src/server/ws_sdk.h:11,
from /home/chenya/code/dts/src/main.cpp:3:
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/http/response.hpp:256:40: error: 'set_root_directory' declared as an 'inline' field
inline self& set_root_directory(std::filesystem::path path)
^~~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/http/response.hpp:256:16: error: expected ';' at end of member declaration
inline self& set_root_directory(std::filesystem::path path)
^~~~~~~~~~~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/http/response.hpp:256:40: error: 'std::filesystem' has not been declared
inline self& set_root_directory(std::filesystem::path path)
^~~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/http/response.hpp:256:57: error: expected ')' before 'path'
inline self& set_root_directory(std::filesystem::path path)
^~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/http/response.hpp:265:21: error: 'filesystem' in namespace 'std' does not name a type
inline const std::filesystem::path& get_root_directory() noexcept
^~~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/http/response.hpp:347:31: error: 'fill_file' declared as an 'inline' field
inline self& fill_file(std::filesystem::path path,
^~~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/http/response.hpp:347:16: error: expected ';' at end of member declaration
inline self& fill_file(std::filesystem::path path,
^~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/http/response.hpp:347:31: error: 'std::filesystem' has not been declared
inline self& fill_file(std::filesystem::path path,
^~~~~~~~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/http/response.hpp:347:48: error: expected ')' before 'path'
inline self& fill_file(std::filesystem::path path,
^~~~
/home/chenya/code/dts/./thirdparty/asio2/include/asio2/http/response.hpp:419:8: error: 'filesystem' in namespace 'std' does not name a type
std::filesystem::path root_directory = std::filesystem::current_path();
^~~~~~~~~~
我在网上搜索了相关问题,filesystem 在gcc8.0以下版本位置在这里
#include<experimental/filesystem>
看简介,这是一个基于asio的网络框架,相比asio提供了更多的工具方便使用,但是名字叫asio2给人一种asio升级版的意思,这会不会让人误解?
例如KCP客户端通过timer定时发送心跳包(附带时间戳),服务端以此统计延迟。
我这边本地测试出来延迟上百ms,感觉阻塞在内部了?
有些数据包优先级比较高需要立即发送,接口层面上应该有所支持。
例如kcp,当选择阻塞发送时,ikcp_update
应该立即进行一次刷新。
使用Android Studio集成JNI工程时,beast/core/detail/config.hpp:36 检测到__GNUC__版本过低,这个有解决办法吗?NDK版本 21.4.7075529
凌动处理器的平板。循环调用async_send发送消息,延迟很大,开始是两三秒,很快就是延迟3、4分钟。同样的代码在笔记本电脑上就没有这么大延迟,保持在3、4秒钟左右。请问是什么原因?是平板性能跟不上?
假设, 我有一个项目, 其同样需要使用fmt, spdlog, json等库, 且这些库的版本比当前所使用的版本更新.
那么我们需要做什么以规避可能会出现的头文件冲突问题?
有这个疑问是因为我看include/external/json里面是直接用了那个single header, 但假设我所在的项目也有这个single header, 那么是否会直接出现编译错误?
一个IO监听多个端口怎么处理
报错出现在:
\beast\core\detail\config.hpp:36:4: error: Beast requires C++11: gcc version 4.8 or later needed
检查Android ndk版本,gcc为4.9.
更换nkd版本,并手动指定gcc版本为4.9同样报这个错误。
一个服务进程会同时出现tcpsever,tcpclient等业务场景,他们可以公用一个iopool。
Hello,
I need to use RPC is my c++ client, however, for server-side application I have to use C# .net core.
do you know of any compatible C# server library with asio2?
thanks
我使用
server.bind("/ws", websocket::listener<asio2::http_session>{}.
on("message", [](std::shared_ptr<asio2::http_session>& session_ptr, std::string_view data)
{
方式创建ws服务,功能上需要ws客户端链接后ws服务应答后的通知,服务再处理业务,看了代码没有找到这种回调接口。
udp client 通过 send 发送消息后
怎样在当前线程获取server端对该消息返回的数据?
asio2\include\asio2\bho\beast\core\async_base.hpp(246): error C2665: “bho::beast::detail::execution_work_guard::execution_work_guard”: 没有重载函数可以转换所有参数类型
报这个错。
使用asio-1-27-0才会出现
用asio-1-26-0不会
在java的netty中内部实现了buffer的对象池,需要用的时候拿一个出来,这样buffer的回收都不用了
组包经常会用到自动扩容
rt
同#4
如果有可能的话 个人建议以后改一下名字
首先,惊人的项目! 你值得高度赞扬。
其次,正如标题所说,这与其说是问题,不如说是一个问题。 我一直在网上追逐很多东西,试图重现这样的东西:https://forum.qt.io/topic/138023/reproduce-windows-iocp-server 但是到目前为止没有成功。
你认为我可以用你的图书馆复制上述内容吗? 从您的示例的初步检查来看,这似乎是可能的。 然而,一些需要的东西对我来说仍然是个问题。
非常感谢您的帮助!
The quic protocol may be a more attractive protocol for reliable udp transmisison. Of cource, the quic implementation is daunting in consideration of the large size of its codebase. But there is an alternative option implemeted by facebook https://github.com/facebookincubator/mvfst/tree/master/quic.
The most important fature is the newer congestion control algorithm BBR.
Just a suggesstion. The author can try it.
如题
tcp client接收消息的时候出现“read error found”提示,请问是什么原因导致的呢?
第一次Startup(...)会成功,Shutdown()后,再次使用相同的参数Startup会报错,如不调用local_endpoint(...),目前来看没什么问题,但是请问该如何设置本地端口?
p_bool RpcTerminal::Startup(const p_string& host, const p_string& port, const p_string& local_port)
{
if (rpc_client_ == p_nullptr)
{
rpc_client_ = std::make_unique<asio2::rpc_client>();
}
rpc_client_->default_timeout(std::chrono::seconds(kDefaultRpcClientCallTimeoutInSec));
if (rpc_client_->is_started())
{
return true;
}
rpc_client_->local_endpoint(asio::ip::tcp::v4(), atoi(local_port.c_str()));
//TODO: Implement the callbacks.
rpc_client_->bind_connect([&](asio::error_code ec) {})
;
return rpc_client_->start(host, port);
}
void RpcTerminal::Shutdown()
{
if (rpc_client_ != p_nullptr)
{
rpc_client_->stop();
rpc_client_ = p_nullptr;
}
}
on test demo ssl_http_client line 40
auto reprss = asio2::https_client::execute("https://github.com/freefq/free", std::chrono::seconds(60));
always got a 404 page
the reason is we suppose to ack a requirement to link https://github.com/freefq/free but execute function result is sending a https://github.com/freefq%2Ffree requirement
my chrome browse got right result by https://github.com/freefq/free also failed 404 page by https://github.com/freefq%2Ffree
reason on code:
on file http_util.hpp line 231 to line 241 percent encoding all remaining url
here is my thoughts:
i think one symbol need percent encoding is to avoid conflicting with its real meaning
a link is like a filesystem,symbol '/' mean levels
suppose github.com/freefq/free to C:/test/scene1
change C:/test/scene1 to C:/test%2Fscene1 outcome is not a valid address
the scene percent encoding can make sense is the folder name with a ‘/’ inside
so we assume 'sce/ne1' is a folder name then percent encoding it change to C:/test/sce%2Fne1
percent encoding on url should be a user initiate behavior so the first paramter should fill with a url already percent-encoded by user when using asio2::https_client::execute
and now my solve is simpling block percent encoding on file http_util.hpp line 231 to line 241
from
if (/*std::isalnum(c) || */unreserved_char[c])
{
r += static_cast<rvalue_type>(c);
}
else
{
r += static_cast<rvalue_type>('%');
rvalue_type h = rvalue_type(c >> 4);
r += h > rvalue_type(9) ? rvalue_type(h + 55) : rvalue_type(h + 48);
rvalue_type l = rvalue_type(c % 16);
r += l > rvalue_type(9) ? rvalue_type(l + 55) : rvalue_type(l + 48);
}
to
r += static_cast<rvalue_type>(c);
and got the correct page result
i dont konw is correct or not or may cause other error on some scene
看代码里面有ASIO_STANDALONE ,
但是提示// Must define ASIO_STANDALONE, otherwise compilation fails.
询问一下有支持这部分的计划嘛?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.