Thread: Web interface/pipes questions

  1. #1
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413

    Web interface/pipes questions

    First off, I know very little about networking programming, like, I know how to use cURL from C and how to make simple socket connections.

    Basically, I'm looking for a way to encapsulate a persistent command-line program, namely an interpreter, using pipes and send/receive that text via a web interface. It'd be a lot like this: MathCloud - Share Matlab / Octave scripts and data here and do your computing in the cloud. You'd see your past input/output and give new commands to a program running on the server. That site uses Java server pages and I don't want to use Java.

    It sounds like it'd be a trivial task but I really have no idea where to start. It'd be dead simple if you just had to run one command in the interpreter and then exit, you could do that with PHP I believe. The trick here is keeping that interpreter open so that all your variables and stuff are persistent.

    I'd like to do this with a scripting language if possible...like...I'm thinking I could call a Python script that would connect to an existing running process of the interpreter (can you encapsulate an already running program with pipes?), send the command and get the output, and send that back to the client. I'm also not really sure how that would come together on the client side, like I guess I could use JavaScript (to keep record of the inputs) and input forms to POST commands to the script.

    I mostly want to figure this out on my own, but a point in the right direction would be great. Thanks in advance for reading this.

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    I'd probably approach it like this. The interpretter creates a UNIX socket and binds it somewhere in the filesystem, say, /var/my_interpretter/socket. Whenever this socket is opened, the interpretter will read commands from it, and write results to it. So now, anybody can talk to the interpretter through this socket.

    Then, on the web server, write a PHP script which opens the socket, sends the commands (from a web form) to it, reads the response, then closes the socket. The response is returned to the web client.

    If you want to run the interpretter on a different host from the web server, then you'd use a standard TCP/IP socket instead of a UNIX socket. Bear security in mind when doing this. If you want to avoid sockets altogether and use pipes instead, you'll need two of them: one for writing to the interpretter and one for reading from it. Pipes aren't bidirectional.

    As always, the details will be the fun part. But that's a good starting point, I think.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Thanks brewbuck

  4. #4
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Been totally spoiled by Python, which is funny because I posted on this same forum a year ago about how bad Python is because it's too easy. I know I'm a hypocrite.

    Using SocketServer and subprocess to encapsulate the interpreter with pipes and connect it to a port (socket). On the client side, using AJAX/XmlHttpRequest for I/O. Too sweet.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic questions about web services development
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 07-13-2008, 09:30 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Consuming same Web Service multiple times
    By cfriend in forum C# Programming
    Replies: 2
    Last Post: 01-10-2006, 09:59 AM
  4. Barrage Of Questions...Theory impossible? File IO on Web Domain?
    By MagiZedd in forum Windows Programming
    Replies: 0
    Last Post: 10-24-2001, 08:13 PM