I created a Websocket server in Python that receives data (maximum 300 bytes) from a browser, and in python when creating server/client you always use asyncio or threading, so you would be able to listen continuously while at the same time data is processed or handling other clients.
My question is it required in C++ too?
I try to make the C++ program get this data, process it, and store it, do I need to use multithreading/async for it too?
Bonus question
I on the fence between setting a separate python socket server and a socket C++ client to send the data
Or using shared memories
I was told shared memories is harder, and is more for if I need to share a lot of data very fast
But still want your opinion
Top comments (1)
Short answer: No, threading/async is not strictly required, but it depends on your use case.
When you DON'T need threading
If you have a simple scenario with:
A simple blocking loop works fine:
When you DO need threading/async
C++ options:
Bonus: Sockets vs Shared Memory
My recommendation: Start with sockets — they're simpler and easier to debug. Only switch to shared memory if profiling shows it's a bottleneck.
For 300 bytes from a browser, sockets are more than enough!