0

Suppose I have a C++ application that would read keyboard inputs and print it to console whenever a character is pressed. So if I press "hello" (without the cursor having to be in a specific window), the app would print "h", "e", "l", "l", "o" sequentially (without needing "hello" to complete").

I would want to send this sequence to another application that is written in another language e.g. C# in Unity or Python. So in a sense, C++ is like a server that is streaming strings to a C# client. And the client should receive each character immediately as soon as C++ generates it. Client should also be able to send some text to server also. E.g. command to tell the server to pause reading keyboard inputs for a few seconds.

I'm thinking that this should be an IPC (inter-process communication) problem because the client will be in the same machine as the server. We can have multiple clients in the same machine that connects to the same server.

So if we have a server, a C# client, a python client, both clients would receive the same text sequence from the server. And if C# client tells the server to stop, the python client also would not receive the text as well.

The OS that it should work on is Windows. But if it would work on both Unix and Windows then that's better.

What's a good IPC approach that fits all my requirements?

PS. In real use case, I would send 1,000 characters string 100 times a second to the client instead of sending keystrokes. But it would still be a very tiny amount because it's in the same computer.

1

The server can use UDP multicast to publish the characters, that way it does not really need to care about what clients exactly are listening. The clients just need to register to the multicast group and listen what the server is sending.

In addition, for the feature of pausing, create a (unicast) UDP socket the server is listening on and that the clients can send a message to.

You can be sure UDP is supported by all languages you need, and the overhead is also low. Sure there may be better approaches for simple IPC like that that don't need the network stack, but using UDP is simple, you will easily find documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.