Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Is there a way to use Client.readString() propperly outside of the draw() function?

$
0
0
Hi. Can you help me?

Currently I have the following code, and everything is fine with it, except that I'd like to read the incoming data without recurring to the draw function. Specially since I don't need a draw function in the program I'm writing. While loop doesn't seem to work...

  1. import processing.net.*;

    String data;
    Client c;
    String hostvar;
    String getReq;


    void setup() {

    hostvar = "www.processing.org";
    getReq = "/reference";

    c = new Client(this, hostvar, 80); // Connect to server on port 80

    //c.write("GET / HTTP/1.1\r\n"); // Use the HTTP "GET" command to ask for a Web page

    c.write("GET "+ getReq + " HTTP/1.1\r\n");
    c.write("Host:" + hostvar + "\r\n");
    c.write("User-Agent: Opera/9.80 (Windows NT 6.1; WOW64) Presto/2.12.388 Version/12.12; en-US; rv:1.9.0.7) Gecko/2009021906 Firefox/3.0.7\n");
    c.write("\r\n");

    while (c.available() > 0) { // This code doesn't work. .
    data = c.readString(); // // This code doesn't work. .
    println(data); // This code doesn't work. .
    }// This code doesn't work. .
    }

    void draw() {

    if (c.available() > 0) { // If there's incoming data from the client...
    data = c.readString(); // ...then grab it and print it //this code works...
    println(data);
    }
    }
---
For if reason has once undoubted right on its side, it will not allow itself to be confined to set limits, by vague recommendations of moderation. -Immanuel Kant

Viewing all articles
Browse latest Browse all 1768

Trending Articles