Skip to content
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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

Burke-Daniel
Copy link
Collaborator

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 and udp_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:

  1. The actual C++ networking code - using ASIO, there is now a tcp and udp client that can be used to connect to and communicate with a respective server. This uses async a fair bit, and is a bit magical, so I can explain more in depth how it works if necessary.
  2. The unit tests - I have used catch to unit test the Message class and its methods for correctness. Feel free to build and run these tests. Going forward we need to focus on testing thoroughly all of our new code
  3. The python testing scripts - I dropped these in a tools directory. Not sure if this is the most appropriate spot for them or not so lmk but this is what I used to test the functionality of the C++ code.

Burke-Daniel and others added 11 commits May 9, 2021 14:51
… 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.
@Burke-Daniel Burke-Daniel force-pushed the feature/FC/networking-primitives branch from 7cd6f2d to a31514f Compare May 9, 2021 17:22
asio::async_connect(m_socket, endpoints,
[this, &endpoints](std::error_code ec, tcp::endpoint)
{
if (!ec)
Copy link
Collaborator Author

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

Copy link
Collaborator Author

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>
Copy link
Collaborator Author

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

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant