Interprocess communication with a Daemon

前端 未结 3 766
隐瞒了意图╮
隐瞒了意图╮ 2021-02-01 08:02

I want to implement a Unix daemon (let\'s call it myUnixd), and want the user to be able to interact with this daemon via the command line, for example:



        
相关标签:
3条回答
  • 2021-02-01 08:19

    One could also use Remote Procedure Call (RPC) for such client-server communication. There are different types of messages (protocols) that can be used together with it, one of them is JSON.

    The JSON-RPC protocol is very well accepted for such tasks. You can find different tools and libraries to embed in your software. A quick search on google gives this C library. The advantage of such libraries is that from a JSON specification file, where you define all your remote function calls, it creates client and/or server stubs that you can just use in your code out of the box.

    As a listener one can use sockets, as the other responses state, or just an embedded HTTP server like microhttpd (and libcurl for the client). There are plenty of examples out there to just reuse. HTTP allows you also to run your client behind a proxy.

    0 讨论(0)
  • 2021-02-01 08:35

    use tcp socket if you want to use telnet to communicate with your daemon.

    0 讨论(0)
  • 2021-02-01 08:39

    Use Berkeley sockets. Specifically, you can create a "UNIX domain socket" (otherwise known as a "local domain socket," which will create what looks like a text file. Write to the text file to send text to the daemon, read from it to receive text from the daemon. You can implement this with a few function calls.

    If you want something more advanced, you can also use DBus, which offers a more sophisticated interface, but which is more complicated to learn.

    0 讨论(0)
提交回复
热议问题