-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
135 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
name: ci | ||
on: | ||
pull_request: | ||
branches: | ||
- dev | ||
- master | ||
push: | ||
branches: | ||
- dev | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#pragma once | ||
|
||
#include <srs/data/DataStructsFormat.hpp> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
cmake_minimum_required(VERSION 3.22) | ||
project(readUDP) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
add_executable(main main.cpp) | ||
|
||
find_package(Boost REQUIRED) | ||
find_package(srs REQUIRED) | ||
find_package(fmt REQUIRED) | ||
|
||
target_link_libraries(main PRIVATE Boost::boost srs::srs fmt::fmt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <boost/asio.hpp> | ||
#include <srs/format.hpp> | ||
#include <srs/srs.hpp> | ||
|
||
constexpr auto PORT = "11111"; | ||
constexpr auto IP_ADDR = "localhost"; | ||
constexpr auto INPUT_BUFFER_SIZE = 10000; | ||
namespace asio = boost::asio; | ||
using udp = asio::ip::udp; | ||
|
||
namespace | ||
{ | ||
auto create_socket_from_ip_port(asio::io_context& context, const std::string& ip_addr, const std::string& port) | ||
{ | ||
auto resolver = udp::resolver{ context }; | ||
auto udp_endpoints = resolver.resolve(udp::v4(), ip_addr, port); | ||
auto endpoint = *udp_endpoints.begin(); | ||
return udp::socket{ context, endpoint }; | ||
} | ||
|
||
} // namespace | ||
|
||
class MsgReceiver | ||
{ | ||
public: | ||
explicit MsgReceiver(udp::socket socket) | ||
: socket_{ std::move(socket) } | ||
{ | ||
} | ||
|
||
void listen() | ||
{ | ||
socket_.async_receive(asio::buffer(msg_buffer_), | ||
[this](auto error_code, auto byte_read) | ||
{ | ||
auto msg = std::string_view{ msg_buffer_.data(), byte_read }; | ||
if (!error_code) | ||
{ | ||
const auto& struct_data = msg_reader_.convert(msg); | ||
fmt::print("{}\n", struct_data); | ||
} | ||
listen(); | ||
}); | ||
} | ||
|
||
private: | ||
udp::socket socket_; | ||
std::array<char, INPUT_BUFFER_SIZE> msg_buffer_{}; | ||
srs::ProtoMsgReader msg_reader_; | ||
}; | ||
|
||
auto main() -> int | ||
{ | ||
auto io_context = asio::io_context{}; | ||
|
||
auto msg_receiver = MsgReceiver{ create_socket_from_ip_port(io_context, IP_ADDR, PORT) }; | ||
msg_receiver.listen(); | ||
io_context.run(); | ||
|
||
return 0; | ||
} |