目前我有以下代码,一切都很好,除了我想从主机读取传入数据而不重复绘制函数。特别是因为我在编写的程序中不需要绘图功能。虽然循环似乎不起作用......
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);
}
}