How to setup a client and a server that can both send/receive simultaneously?

Hey everyone!
I am a bit new to this, so forgive me if I misunderstand some of these terms. At the moment, I have working a laptop that acts as a client and a Raspberry Pi that acts as a server. The client can send something to the server and the server can send something back to the client, but they can never do this at the same time (synchronous communication). Here is the code for the client and the server. https://github.com/jmoore-15/Client-Server.

Here is a helpful image to show you what is going on in my scenario https://imgur.com/nxZmcPT

What I would like is for the client to constantly be sending thruster commands to the Pi while simultaneously receiving sensor data from the Pi. This would be asynchronous communication, right?

I am having a lot of trouble figuring out where to start with this in C++. I cannot find any guides that help you set something like this up. Does anyone have any example code or guides that could aid in this?
Thank you so much!
Last edited on
The link to github is broken.
Communication is one sending and the other listening. They can't just shout at any time uncontrollably. The agreement on how they exchange information is called a protocol.

There are several examples of asynchronous communication kicking around already. But we'd need a better idea of what you want before proposing something specific.

However, it's normal to have multiple socket connections for different kinds of simultaneous communications. For example, in HTTP2 there can be a separate connection maintained for asynchrounous updates via websockets.

Also, maybe TCP isn't what need, and a UDP datagram protocol might be more appropriate. It all depends on what you need.
Last edited on
What I would like is for the client to constantly be sending thruster commands to the Pi while simultaneously receiving sensor data from the Pi.

If you had two processes on both devices and two connections between the devices, one for thruster and another for sensor, then these two communications would occur independently and as simultaneously as the respective OS and hardware allow them to execute. Does that transform the question into "How do two processes on same machine communicate?"

Those two processes can be implemented with one process that has multiple threads: http://www.cplusplus.com/reference/multithreading/
The link to github is broken.

That's because the OP didn't separate the URL from the full stop at the end of the sentence, so it became part of the link.

The link should be https://github.com/jmoore-15/Client-Server .

Multiple threads can be used as suggested to solve this issue, but if such development might still be too taxing, then maybe try using a communications manager that already does all the nitty gritty for you.

Checkout this link: http://www.shankodev.com/Libs/KLibNet/items/KTransmissionMgr/KTransmissionMgr_Page_00.htm for one that could be used for both windows and linux environments
Topic archived. No new replies allowed.