54 lines
1.5 KiB
C++
54 lines
1.5 KiB
C++
#include <asio/ip/tcp.hpp>
|
|
#include <iostream>
|
|
|
|
#include "../net/adc_netproto.h"
|
|
#include "../net/asio/adc_netservice_asio.h"
|
|
|
|
int main()
|
|
{
|
|
asio::ip::tcp::endpoint ept_s(asio::ip::tcp::v4(), 9999);
|
|
// asio::ip::tcp::endpoint ept_c(asio::ip::make_address_v4("127.0.0.1"), 9999);
|
|
asio::ip::tcp::endpoint ept_c(asio::ip::tcp::v4(), 9999);
|
|
|
|
asio::io_context ctx;
|
|
|
|
adc::impl::AdcNetServiceASIOBase<asio::ip::tcp, adc::AdcStopSeqSessionProto<>> srv(ctx);
|
|
|
|
adc::impl::AdcNetServiceASIOBase<asio::ip::tcp, adc::AdcStopSeqSessionProto<>>::asio_async_ctx_t srv_ctx;
|
|
srv_ctx.accept_comp_token = [](std::error_code ec) {
|
|
|
|
};
|
|
|
|
// srv.asyncAccept(ept_s, srv_ctx, std::chrono::seconds(120));
|
|
// srv.asyncConnect(ept_c, [](std::error_code ec) {
|
|
|
|
// });
|
|
|
|
// adc::impl::AdcNetServiceASIOBase<asio::ip::tcp, adc::AdcStopSeqSessionProto<>>::contx_t s_ctx;
|
|
|
|
// srv.asyncConnect(ept_c, s_ctx);
|
|
// auto res = srv.asyncConnect(ept_c, asio::use_awaitable);
|
|
|
|
srv.asyncAccept(ept_c, [&srv](std::error_code ec) {
|
|
if (!ec) {
|
|
std::cout << "New connection\n";
|
|
|
|
srv.asyncReceive(
|
|
[](std::error_code ec, std::string msg) {
|
|
if (!ec) {
|
|
std::cout << "Received: " << msg << "\n";
|
|
}
|
|
},
|
|
std::chrono::minutes(3));
|
|
} else {
|
|
std::cout << "ACCEPT ERR: " << ec.message() << "\n";
|
|
}
|
|
});
|
|
|
|
ctx.run();
|
|
|
|
std::cout << "Exit!\n";
|
|
|
|
return 0;
|
|
}
|