I ported my Arduino web page “server” to Processing as a warm up exercise.
There are better ways to deal with strings but just left it as is for now.
// Web page is at http://127.0.0.1:20000/1
// Count on page increases with each refresh of page
// The Processing console shows request from web page
import processing.net.*;
Server s;
Client c;
String input;
int data[];
int count = 0;
int val = 0;
void setup()
{
size(200, 200);
// Starts a myServer on port 5204
s = new Server(this, 20000);
}
void draw()
{
background(0);
c = s.available();
if (c != null)
{
input = c.readString();
println("Received:\r\n"+ input);
input = input.substring(0, input.indexOf("\r\n")); // Only up to the newline
data = int(split(input, ' ')); // Split values into an array
println(input);
//printArray(data);
}
if (input != null)
{
//if (input.equals("GET /1 HTTP/1.1") == true)
// println("/1");
//if (input.equals("GET /favicon.ico HTTP/1.1") == true)
// println("/favicon.ico");
if (input.equals("GET /1 HTTP/1.1") == true)
{
webPage1();
count++;
println("Count sent: " + count);
println();
println("*************************************************************");
println();
}
}
input = null;
}
void webPage1()
{
s.write("HTTP/1.1 200 OK\r\n");
s.write("Content-Length: ");
s.write("131");
s.write("\r\n");
s.write("Content-Type: text/html\r\n");
s.write("Connection: close\r\n\r\n");
s.write("<!DOCTYPE html>\r\n");
s.write("<head>\r\n");
s.write("<link rel=\"icon\" href=\"data:,\">"); // Does not request fav.icon now!
s.write("</head>\r\n");
s.write("<html>\r\n");
s.write("<body>\r\n");
s.write("<h3>Hello Folks!</h3>\r\n");
s.write("<h3>" + count + "\r\n");
s.write("</body>\r\n");
s.write("</html>\r\n\r\n");
s.write("*******************************************************************");
}
Next step is to install WAMP and have Processing communicate with it:
Lot’s of options there to explore.
glv