Skip to content

Commit

Permalink
Add code for testing TCP client
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Burke-Daniel committed May 9, 2021
1 parent a4c65ff commit 7cd6f2d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Subsurface/FlightComputer/include/NetClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ class TcpClient
{
if (!ec)
{
std::cout << m_readMessage.data() << std::endl;
m_readMessage.decodeHeader();
Person person;
if (m_readMessage.deserialize(person))
{
std::cout << "Successfully parsed data!" << std::endl;
std::cout << "Email: " << person.email() << std::endl;
std::cout << "Name: " << person.name() << std::endl;
}
readHeader();
}
else
Expand Down
25 changes: 23 additions & 2 deletions Subsurface/FlightComputer/src/FlightComputer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ int main(int argc, char* argv[])
{
asio::io_context context;

udp::resolver resolver(context);
// UDP Test
/*udp::resolver resolver(context);
auto endpoints = resolver.resolve(udp::v4(), "127.0.0.1", "10000");
UdpClient<Person> client(context, endpoints);
Expand All @@ -33,8 +34,28 @@ int main(int argc, char* argv[])
client.write(message);
LOG(INFO) << client.getReadMessage().body();
std::this_thread::sleep_for(std::chrono::duration(std::chrono::milliseconds(1000)));
}
}*/

// TCP Test
tcp::resolver resolver(context);
auto endpoints = resolver.resolve(tcp::v4(), "127.0.0.1", "10000");
TcpClient<Person> client(context, endpoints);

std::thread t1([&context]() { context.run(); });
while (true)
{
static int count = 0;
Person person;
person.set_name("Daniel Burke");
person.set_email("[email protected]");
auto phone = person.add_phones();

Message<Person> message(person);
client.write(message);
LOG(INFO) << client.getReadMessage().body();
std::this_thread::sleep_for(std::chrono::duration(std::chrono::milliseconds(1000)));
}

client.close();
t1.join();

Expand Down

0 comments on commit 7cd6f2d

Please sign in to comment.