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 › internet > processing
Page Index Toggle Pages: 1
internet > processing (Read 2656 times)
internet > processing
Jul 25th, 2005, 5:44am
 
What's the best way to send simple information that a user enters in webpage form, to P5 ? The information isn't exactly time-critical, but i'd like something better then puting all the data in a txt.xml file and periodically reading that from processing. I tried was thinking about using Flash on the web-page, flash sends an XML message to a FLOSC server that sends an OSC message to P5. So far, when I try to start the FLOSC server I get a "Exception in thread "main" java.lang.NoClassDefFoundError: Gateway/class" error Sad
Any idea why ?

Any better ideas ?
Re: internet > processing
Reply #1 - Jul 25th, 2005, 11:08am
 
You could, theoreticly, use the net library, and write a very very simple web server in processing, and set the web form to submit data to your computer on a certain port that you have processing listening on.

all you'd need to do, is listen for a connection on a specified port, read all the data being sent, then send a very simple response, such as:
Code:
200 OK
Content-type: text/plain

Thankyou.


Close the connection, then look through the data recieved, and you'll see how the form data is passed.


This is probably overkill, and assumes that you'll be able to setup your form to point at your computer, with no firewall problems or the like.
Re: internet > processing
Reply #2 - Jul 25th, 2005, 2:45pm
 
"use the net library, and write a very very simple web server in processing, and set the web form to submit data to your computer on a certain port that you have processing listening on. "
This seems logical, but the "set the web form to submit data to your computer" part I don't get. I used the NET library to send information between computers running P5, but how do I set a web page to send information to a P5 comp ?

Thx.
Re: internet > processing
Reply #3 - Jul 25th, 2005, 2:54pm
 
you can set the "submit" target fo a form to be anywhere, so you could say:

<form name="myform" method="GET" action="http://my-computer.ip.address:1234/">
.. normal form stuff ...
</form>

That will make the person's browser connect to your computer on port 1234 to submit the contents of the form.

So all you need to do is write your sketch with the net library to listen on port 1234, and anyone filling in the form should connect straight to your sketch, and submit the data.
Re: internet > processing
Reply #4 - Jul 25th, 2005, 7:08pm
 
wow, I had no idea that would work. I'll try it, if it works, it's perfect for what I need. Thanks.
Re: internet > processing
Reply #5 - Jul 25th, 2005, 8:23pm
 
it appears to be working, sort of.

Code:

import processing.net.*;
int port = 9999;
Server myServer;

void setup() {
size(400, 400);
background(0);
myServer = new Server(this, port); // Starts a server on specified port
}

void draw() { }

void serverEvent(Server someServer, Client someClient) {
println("We have a new client: " + someClient.ip());
myServer.write("200 OK");
myServer.write("Content-type: text/plain");
myServer.write("Thankyou.");
}


The first problem is that the webpage does not receive the answer, or the answer isn't well formated or something, it just gives a timeout after a while, but I think I can work around that.

The other problem is more serious: I've looked into the NET docs and there is no READ command for the server, although there is a WRITE command for the client. I tried the examples in the docs, and the example for the client.write doesn't give any error but doesn't affect the server in any way either (wich is normal, the server doesn't have a read command in it).

So the question is, how do I retrieve information on the server from the web page ?

Thanks.
Re: internet > processing
Reply #6 - Jul 26th, 2005, 11:44am
 
Personally, I wouldn't use the ServerEvent thing, since I'm not quite sure how that's supposed to work.

I'd try somethign along the lines of the documentation here: http://processing.org/reference/libraries/net/Server_available_.html

That way you can accept a connection, then send/recieve data to the specific connected client.
Re: internet > processing
Reply #7 - Jul 26th, 2005, 12:47pm
 
Why not just do this all in javascript? Just set it up the form to call a javascript which calls a method in the applet with the data as an argument.
Re: internet > processing
Reply #8 - Jul 26th, 2005, 2:01pm
 
Oh, I see. The server event thing is working, I just wasn't reading stuff with it, it just detects when a client connects. The thisClient.readString(); seems the way to go.


I'm not doing this in javascript because the input is from the internet, from a web page, wich sends the data to a processing server that interprets it, wich is on another server, and it doesnt't run as an applet.

thanks
Re: internet > processing
Reply #9 - Aug 2nd, 2005, 10:21am
 
i'd actually use a PHP file to catch the posted form, echo the results into a Param (http://processing.org/reference/param_.html) which processing can read easily..

HTML send file:
Code:

// POST.HTML
<form method="POST" action="catch.php">
<input type="textfield" name="field" size="15">
<input type="submit" name="sub" value="Send">
</form>


PHP catch file:
Code:

// CATCH.PHP
<applet code="applet" archive="applet.jar" width=100 height=100>
<param name="field" VALUE="<? echo $_POST['field']; ?>"> </applet>

hope you get it working Smiley good luck

-seltar
Page Index Toggle Pages: 1