digitalmars.D.learn - remote execute program
- Cecil Ward (26/26) Mar 22 2018 I am wanting to write a short program (on a ‘server’ you could
- Kagamin (2/2) Mar 23 2018 You can just read the whole request into a buffer and parse it
- Cecil Ward (2/4) Mar 23 2018 Agreed.
- Kagamin (2/2) Mar 23 2018 Or this:
- Cecil Ward (7/33) Mar 23 2018 It's not really a D question, in a sense, it's just that I am out
- =?UTF-8?Q?Ali_=c3=87ehreli?= (30/39) Mar 23 2018 A popular way of doing it is using a REST API. Your http server should
I am wanting to write a short program (on a ‘server’ you could say) that takes a command, runs it (as on the command line, so an executable with arguments or a shell command) and returns a 3-tuple with an int for the return code, plus the textual outputs that it generates to stdout and stderr. I can see a number of suitable routines in the D runtime libraries, which are already D-ified to save me a some trouble mindlessly converting code from C. Where I could do with some help is as follows: I'm needing to send the commands to a remote box using http has to be used because the local-end program (on an iPad) that I have to interfacing to can only speak http/https, and can not handle just a straight eg TCP connection. Despite the overheads from using http, if I can employ gzip compression on the link then that will be a big gain. Could anyone give me some general pointers for where to look? The server box is a linux machine. I'm a very experienced professional C programmer but amazingly have never done anything with *nix in general or http-related C libraries. I asked a question in this forum earlier about general low-level networking, but now this requirement has come up that mandates the use of very simple http and needs only synchronous operations. The impressive framework that is vibe.d has already been mentioned, but the amount of reading matter is rather daunting. A simple D example of an http transaction would be very helpful.
Mar 22 2018
You can just read the whole request into a buffer and parse it there.
Mar 23 2018
On Friday, 23 March 2018 at 07:57:33 UTC, Kagamin wrote:You can just read the whole request into a buffer and parse it there.Agreed.
Mar 23 2018
Or this: https://github.com/nextcardgame/lighttp/blob/master/examples/chat.d
Mar 23 2018
On Friday, 23 March 2018 at 01:23:56 UTC, Cecil Ward wrote:I am wanting to write a short program (on a ‘server’ you could say) that takes a command, runs it (as on the command line, so an executable with arguments or a shell command) and returns a 3-tuple with an int for the return code, plus the textual outputs that it generates to stdout and stderr. I can see a number of suitable routines in the D runtime libraries, which are already D-ified to save me a some trouble mindlessly converting code from C. Where I could do with some help is as follows: I'm needing to send the commands to a remote box using http has to be used because the local-end program (on an iPad) that I have to interfacing to can only speak http/https, and can not handle just a straight eg TCP connection. Despite the overheads from using http, if I can employ gzip compression on the link then that will be a big gain. Could anyone give me some general pointers for where to look? The server box is a linux machine. I'm a very experienced professional C programmer but amazingly have never done anything with *nix in general or http-related C libraries. I asked a question in this forum earlier about general low-level networking, but now this requirement has come up that mandates the use of very simple http and needs only synchronous operations. The impressive framework that is vibe.d has already been mentioned, but the amount of reading matter is rather daunting. A simple D example of an http transaction would be very helpful.It's not really a D question, in a sense, it's just that I am out of my depth. And wrapping fat C libraries, particularly converting .h files is something that I don't have any experience of, so something ready-cooked in D would b good. What library routines are available - or do I have to start wading through the vastness of vibe.d?
Mar 23 2018
On 03/23/2018 12:25 PM, Cecil Ward wrote:On Friday, 23 March 2018 at 01:23:56 UTC, Cecil Ward wrote:A popular way of doing it is using a REST API. Your http server should direct certain URLs to your service and your service should return the results back. The messages are typically passed as JSON objects. Another method is using grpc but D is not among the official languages at their site.I am wanting to write a short program (on a ‘server’ you could say) that takes a command, runs it (as on the command line, so an executable with arguments or a shell command) and returns a 3-tuple with an int for the return code, plus the textual outputs that it generates to stdout and stderr.If you don't want to use vibe.d I'm sure Adam D. Ruppe's arsd repo has useful modules for you: https://github.com/adamdruppe Regarding vibe.d, I hope others can show you simple examples but a REST service was trivial when I played with vibe.d a few years ago. Look at "Example of a simple HTTP server" at their site: import vibe.vibe; void main() { listenHTTP(":8080", &handleRequest); runApplication(); } void handleRequest(HTTPServerRequest req, HTTPServerResponse res) { if (req.path == "/") res.writeBody("Hello, World!"); } Just implement handleRequest and you're done. But it can be better if your service is RESTful. You can find tutorials here: http://vibed.org/tutorials A fortunate problem is that vibe.d has been easier to use since it started allowing main() written by you. (In the past, it had main() calling your function.) AliThe impressive framework that is vibe.d has already been mentioned, but the amount of reading matter is rather daunting.
Mar 23 2018