What’s an efficient method (preferably simple as well) for communicating with a remote server and allowing the user to ‘interact’ with it (IE submit commands, user interface) via the web browser (IE a text box to input commands, and an text area for output, or various command-less abstracted interfaces)?
I have the ‘standalone’ python code finished for communicating and working(terminal/console based right now). My primary concern is with re-factoring the code to suite the web, which involves establishing a connection (python sockets), and maintaining the connection while the user is logged on.
some further details:
- currently using django framework for the basic back end/templates.
Probably the most efficient would be to set up REST as fmsf said. In general, each command would correspond to an URL with other variables attached:
You could either have these as client actions (they click on a link or submit a form) or as Ajax calls. For Ajax calls, they fill out a complicated form, the form formats it into an acceptable URL with attached data, and sends it to the server. Once the server processes the commands, it returns a result (in XML or JSON format, usually) which is parsed by the browser and displayed on the page.
In a full RESTful app, you’d use the different HTTP methods of POST, GET, PUT, and DELETE to handle records
http://example.com/secret_document/1 [POST]— creates the documenthttp://example.com/secret_document/1 [PUT]— update the documenthttp://example.com/secret_document/1 [GET]— retrieve the documenthttp://example.com/secret_document/1 [DELETE]— delete the documentNot all browsers can support all HTTP methods, however.
In terms of implementation, Django is one option but a bit heavyweight for what you’re looking for. You might want to look at this article which describes in full how you’d set up a lightweight application for responding to web client requests. You can definitely expand it out to add more functionality.