I've written application based on Client class, which opens a client connections, sends a query to a server and gets an answer from it.
Copy code
/** * HTTP Client. * * Starts a network client that connects to a server on port 80, * sends an HTTP 1.0 GET request, and prints the results. * * Note that this code is not necessary for simple HTTP GET request: * Simply calling loadStrings("http://www.processing.org") would do * the same thing as (and more efficiently than) this example. * This example is for people who might want to do something more * complicated later. */
void setup() { size(200, 200); background(50); fill(200); c = new Client(this, "192.168.1.41", 8081); // Connect to server on port 8081 }
void draw() { if (c.available() > 0) { // If there's incoming data from the client... data = c.readString(); // ...then grab it and print it println(data); } }
The application runs good but there are some issues regarding to its processing speed. It takes 5 s to get an answer from the webserver, while it should be possible to get it in less than 1 s by other means.
How can I speed up this? I've been told that this comes from the JVM itself. Is it possible?
Maybe this is a too vague question, but I need to speed up the socket reading in my sketch. Is it possible to get faster answers? The fact is that the webserver answers quite fast (in less than 1 second), while this simple sketch takes longer (around 5 seconds) to get an string with an answer.
I'm writing an sketch to poll an XML file from a webserver and I've successfully implemented the Client class. My issue comes when the webserver is missing, because I need to catch this exception.
Indeed, my webserver may not be available most of the time and I just need to check when it is available and then poll an XML from it.
How can I handle this situation? May I need to implement this sketch with an alternative to Client class?