using processing as a web server and upload files from a browser

edited March 2018 in How To...

Hi all, i would like to do something like that:

  1. setting up a web-server with processing.
  2. the hosted page contain a js script.
  3. the script performe something, or contain a form, and collect some data (maybe some mb)
  4. how can i send it back to the processing based server? like with a csv file or a json or a xml?

Thank you all.

Answers

  • Why do you want to use Processing as a web server? That's really not what Processing is used for...

    It might be possible to call certain Processing functions from a Java web server, but why would you want to?

  • Because i'm only able to use processing... :-)

  • What do you mean "only able"? Do you mean you only know how to use Processing? Or is there some other kind of restriction?

    This really doesn't seem like a job for Processing. Programming languages are like tools. Use the write tool for the job.

  • Well, i mainly use Processing, i learned it coming from Arduino. Recently i started also with JS, and i know there is node.js, but since Processing have the network library i was wondering if what i asked was possible, with it. I understand what you mean, and I'm sure there would be so many ways to do it better with a more specific instruments, but this is true about many thing that usually are also done with Processing, in a kind of sketch scale.

  • The short answer is that no, there isn't a server-side version of Processing.

    You can use Processing from a server-side application, in the same way that you can use Processing from a Java application in eclipse. But if you're looking for something that just works when you press play, you're out of luck.

  • Got it! :-)

  • "You can use Processing from a server-side application"
    Actually, even that is hard, because most web servers are headless, ie. doesn't have a display, while Processing needs a display to start...

  • No, but for "server" i would just mean like a laptop running as server for the period of an event (maybe a week), serving html pages with js and reciving the output of some js function.

  • Actually, even that is hard, because most web servers are headless, ie. doesn't have a display, while Processing needs a display to start...

    I just meant you could use it as a Java library. Presumably to use the PGraphics class or something like that.

    I think OP is barking up the wrong tree, but it's at least possible to use it that way.

  • KevinWorkman, from the feedback of those having tried, even Processing as a library needs a display. The workaround they used is to simulate such display with xvfb.

    secondsky, there are lot of small free web server software available, it is simpler and more efficient to choose one for what you describe. A nice one is Mongoose, for example.

  • KevinWorkman, from the feedback of those having tried, even Processing as a library needs a display.

    I'm not saying you're wrong, but yikes, that doesn't make any sense. Why would I need a display just to create an instance of PGraphics?

    Anyway I've never tried it so I don't know what I'm talking about, but the point stands: what the OP is looking for isn't really a Processing thing.

  • "Why would I need a display just to create an instance of PGraphics?"
    Because Processing has been designed for visual feedback, not as a library.

  • I just successfully deployed a webapp to AWS and used the Processing library to create a PImage on the server side, which passed info about that PImage to the client side.

    So, it's at least possible.

  • edited December 2015
    /**
     * Frameless PApplet (v1.0)
     * by GoToLoop (2014/Dec/19)
     *
     * forum.processing.org/two/discussion/8541/
     * using-processing-as-a-web-server-and-upload-files-from-a-browser
     */
    
    static final void main(final String[] args) {
      final String sketch = Thread.currentThread().getStackTrace()[1].getClassName();
    
      final PApplet p;
      try {
        p = (PApplet) Class.forName(sketch).newInstance();
      }
      catch (final ReflectiveOperationException cause) {
        throw new RuntimeException(cause);
      }
    
      p.args = args;
      p.setup();
    }
    
    PImage img;
    
    void setup() {
      img = createImage(10, 5, ARGB);
    
      for (int i = img.pixels.length; i-- != 0; img.pixels[i] = -(i&1));
      img.updatePixels();
      println(img.pixels);
    }
    
  • Cool! but, can you explain me what you did so? To have a kind of draw() function, could il launch a thread in the setup like:

    void setup() {
    thread("myLoop");
    }
    
    void myLoop()
    {
      while (true)
      {
        // my code here
      }
    }
    
  • edited December 2014

    Well, since Processing's framework isn't active, we have to make our own draw() mechanism.
    Most basic is a simple delay() at the end of the infinite loop! :P

  • But what is the delay() for in this case?

  • Dunno. Try delay(10) or something! Or check how Processing calculates how much it gotta delay().

Sign In or Register to comment.