-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Asio C++ Networking clients and Message structure #41
base: master
Are you sure you want to change the base?
Conversation
… UDP clients The templated message class is to be passed the protobuf class, so that it can be properly serialized and deserialized within the class. The class stores the data as a vector of chars. NetClient contains templated TCP and UDP clients, where the template argument is again the protobuf message type
The null terminator that protobuf was looking for when decoding the message was missing
tcp_server and udp_server can be used to test protobuf, these servers wait for a protobuf packet to be received, and then they deserialize and ensure that the packet is valid, then echo it back to the source.
Copies Paradigm_pb2.py to the net_servers directory for use by the tcp_server and udp_server tools.
Runs an identical test case to the existing UDP client code, and utilizes the tcp_server python tool to echo a Person Protobuf message back and forth.
7cd6f2d
to
a31514f
Compare
asio::async_connect(m_socket, endpoints, | ||
[this, &endpoints](std::error_code ec, tcp::endpoint) | ||
{ | ||
if (!ec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compare against error code value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the reason this is done this way is because error codes are platform-dependent, and not sure that there is an error code indicating success.
using asio::ip::tcp; | ||
using asio::ip::udp; | ||
|
||
template<typename Proto> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably look at making this more general/not templated so we can send multiple protobuf message types over one tcp client
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the reason this is templated is because the Message class is templated. Thus if we wanna make this more general to work with multiple types of Protobuf messages then we need to figure out a way to make the Message class not templated. Possible solution:
- Remove any references to Protobuf template type in Message class (i.e. remove serialize and deserialize methods, and make the Message class just a fixed header, and then a body of variable length). Then if we want to add functionality specific to certain types of Protobuf messages then we just inherit from the Message class, and that will remove templating from the picture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am gonna add some commits to do this and then we can decide how we wanna proceed.
@@ -0,0 +1,236 @@ | |||
#pragma once |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably add in printing of all received/sent data with debug macros
// TCP Test | ||
tcp::resolver resolver(context); | ||
auto endpoints = resolver.resolve(tcp::v4(), "127.0.0.1", "10000"); | ||
TcpClient<Person> client(context, endpoints); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add in callback functionality for received data
Summary
This PR is fairly large, and contains networking client interfaces for TCP and UDP in C++ using the ASIO library. I ended up just adding instructions for installing Protobuf locally, as it was a pain to try and integrate it directly into our repository and build system. This PR also contains some python scripts (
tcp_server.py
andudp_server.py
), as well as a requirements.txt and README for how to use the scripts to test protobuf and networking code.Anyone reviewing this PR should pull and build locally, and test to make sure everything is working. There are three main components to this PR: