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.
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!
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.
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?"
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.