We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › applet - how to send draw info back to server
Page Index Toggle Pages: 1
applet - how to send draw info back to server? (Read 975 times)
applet - how to send draw info back to server?
Jan 26th, 2007, 4:43am
 
I'm new to java & processing-

i am wondering if anyone has advice on how an applet can be used to send information (lines drawn in a processing applet, for example) back to a server hosting the applet. in other words, when someone draws on the applet, i'd like to save the info on the hosting server.  

thx, mj-
Re: applet - how to send draw info back to server?
Reply #1 - Jan 26th, 2007, 10:52am
 
The easiest way is to call

int fromX = 10;
int fromY = 20;
int toX = 100;
int toY = 200;

loadImage("http://yourdomain.com/savaLineDraw.php?"+
          "fromX=" + fromX +
          "fromY=" + fromY +
          "toX=" + toX +
          "toY=" + toY);

otherwise you can look at the network library...

http://processing.org/reference/libraries/net/index.html


Re: applet - how to send draw info back to server?
Reply #2 - Jan 26th, 2007, 3:48pm
 
I believe the reference for loadImage might disagree. Unless it happens to have the ability to save information whilst it is loading an image that it.

You can load information with loadStrings() or loadBytes() online fairly easily.

The save versions of these methods will not work for the web. For that you would need some server side script (PHP, Perl, etc.) or you could use the network library (providing you have an application on your server that can communicate with it) or there's this:

http://processing.org/reference/PrintWriter.html

I haven't played with it yet though, but it sounds like what you want. Perhaps someone else could elaborate with an example
Re: applet - how to send draw info back to server?
Reply #3 - Jan 26th, 2007, 3:55pm
 
stephen's correct in that this will send an http GET to the server, and that php script can simply grab the variables. it's really simple and useful but it has nothing to do with actually loading an image. however, more efficient would be to use loadBytes(), so that it's not trying and failing to parse whatever's returned as image data.

i think there's also an example of using http POST over on processinghacks (or elsewhere on the board?) if you want to send more information than what you can smoosh into the URL.

also when encoding data for the URL, you may need to use java's URLEncoder class, which will properly encode any non-url compliant info you might be sending.
Re: applet - how to send draw info back to server?
Reply #4 - Jan 26th, 2007, 4:41pm
 
actually loadImage is not gonna work at all since it does a filename.endsWith check on the name, since the URL does not end in any of the supported filestypes extensions it's just not doing anything and will return null:
http://dev.processing.org/source/index.cgi/trunk/processing/core/src/processing/core/PApplet.java?view=markup

so, the easiest way to do it is via loadStrings or loadBytes ... if it's just simple data. you might run into a problem with the length of URIs too ..

here are some links:
http://www.shiffman.net/2006/05/02/upload/
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1138221586

F
Re: applet - how to send draw info back to server?
Reply #5 - Jan 27th, 2007, 12:53am
 
hey - thanks for your comments on this - much appreciated!
Will try these suggestions over the next few days.

mj-
Page Index Toggle Pages: 1