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 & HelpIntegration › Sending Images to Server
Page Index Toggle Pages: 1
Sending Images to Server (Read 2392 times)
Sending Images to Server
Aug 17th, 2005, 10:41am
 
I know there has been bits about this subject already posted, but here we go again. I'm just looking for a few basic pointers before I dive in.

I would like to:

. Send an image to the server from my local P5 due to webcam usage
. Have an applet on server that when viewed will display this image
. The number of images grows so my remote server based applet would need to reflect changes.

I'm thinking that I might set up a dir on server that the remote applet looks at and pulls in images one at a time, displays them and then loops. This directory can contain a flexible number of files, the names of which are sequential time stamped.

I'd need a bsic security measure that prevented my remote applet from trying to open a file being transfered from my local P5, but that's about it I think.

I could then just dump files to this dir from my local P5 applet that I'm running.

I've done some basic stuff with the File class, but would appreciate any pointers.

Thanks
Re: Sending Images to Server
Reply #1 - Aug 17th, 2005, 11:34am
 
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=VideoCamera;action=display;num=1117194066

Check that out for posting images to web..
And by just changing some small stuff the phpfile, you can save files with a given name, and timestamp..

$filename = "wcam".time().".jpg"; // or something

Hope this is enough pointers for you to have something to work with..
Good luck Smiley
Re: Sending Images to Server
Reply #2 - Aug 17th, 2005, 11:59am
 

A great start,

Thanks.
Re: Sending Images to Server
Reply #3 - Aug 17th, 2005, 1:19pm
 

I used the .date(U). epoch stamp in the end. My only issue now is speed. Is there a way of sending files to the server without hanging processing.

Running as somekind of background task would be ideal, given that waiting for servers etc. can be time consuming.

I was hoping (he laughs!) for a smooth running sketch that just passed information discretely to the server. Am I pi**ing in the wind here?
Re: Sending Images to Server
Reply #4 - Aug 17th, 2005, 1:50pm
 
Depending on how quickly you need to send them, you can run a separate thread to pass the images in the background.

First, you create a class which takes an image and uploads it to your server.  Make it implement Runnable, and have a public void run() method...

Code:


class UploadRunner implements Runnable {
 PImage toupload;
 UploadRunner(PImage toupload) {
   this.toupload = toupload;
 }
 public void run() {
   // image uploading magic goes here
 }
}



Then create a new thread with your runnable object, and start it.

Code:


PImage imageToUpload = copy(); // or something
Thread uploadingThread = new Thread(new UploadRunner(imageToUpload));
uploadingThread.start();



I think Processing has ways to make threads behave nicely when stopping and starting a sketch (perhaps search for registerDispose or some-such on this forum update: here).  The Sun Java tutorial on threads is also worth reading.

Word to the wise: I wouldn't imagine that starting a thread every frame was a sensible thing to do.
Re: Sending Images to Server
Reply #5 - Aug 17th, 2005, 4:55pm
 

Thanks Tom,

I've got a basic version running on the Thread code you supplied.

I'm a little concerned over the dispose(); and stop(); methods as I've recently discovered they aren't guaranteed. I wonder if this affects the instantiation of a new thread?


I'll check out the Java docs, as I looked at Threads a while back and can't remember much about them, apart from the obvious.
Re: Sending Images to Server
Reply #6 - Aug 17th, 2005, 7:32pm
 
if you're starting new threads on your own, they should die out just fine.. you don't need to stop them (stopping a thread is a no-no anyway) you just let their run() method finish up on its own and the object will be garbage collected.

the stop() and registerDispose() thing is more about a separate, continuously running thread than launching several new ones that are simply used to complete their own asynchronous operation.

...at least that's what i understand from your approach here.
Page Index Toggle Pages: 1