1 year ago
#282478
RobbingDaHood
How to implement a "Command line interface server"
If I were creating a webserver then there would be one thread listening to port 8080 and every time there was a new HTTP request then it would trigger some logic in the server. I want to implement the same but instead of listening on port 8080 for HTTP requests, then it would listen for commands from the local operating system (OS) on a command-line interface. These commands can come from any terminal in the OS in the same way as HTTP requests can come from any sender that can access port 8080 on the OS.
I hope I am able to implement an OS-agnostic implementation of this idea in rust. I did try googling this idea without much luck; Likely because I am missing the terminology of this idea.
To clarify one use case:
- In one terminal I start my "CLI server": Example:
cli_server start
- In another terminal I make a "CLI request" to the server and the server will handle the request and respond. The response should be pasted on std.out on the requesting terminal. Example:
cli_server fetch_note id-22
orcli_server update_note data_in_file.json
The Server should keep alive until asked to shutdown. It is not known how many independent terminals will access the server at a time.
What I imagine I need is some code similar to the code that listens on port 8080.
It is fine to split the code in a cli_server
and cli_client
if that makes the answer more simple (or possible).
I do know that I could just implement a web server and use curl to hit port 8080. I am prepared for this as a workaround in case there is no answer to this question. I am interested in an answer to this question out of curiosity and also because that would be a neater solution in my case.
Thanks for reading and I hope my question is not too open ended.
multithreading
rust
command-line-interface
multi-user
0 Answers
Your Answer