// bug606 // // 2007-August-07 djones // // This illustrates bug 606 in the "readStringUntil" function in the Network library // There is a similar bug (96) in the "readBytesUntil" function in the Serial library // The fix has already been posted in the processing bugs database, ... // ... we just need someone to incorporate the fix(es) into the libraries import processing.net.*; Client myClient; String dataString; byte[] dataBytes = new byte[512]; int len; boolean toggle = false; void setup() { size(400,400); frameRate(1); // open a connection to the local FTP daemon // this probably needs to be enabled using Mac System Preferences // or change "localhost" to be another FTP server you know about ... myClient = new Client(this, "localhost", 21); } void draw() { // send a command to the FTP server so it will generate some output if (random(0,1) < 0.25) { myClient.write("help\n"); } println("----- ----- ----- ----- ----- ----- ----- -----\n"); if (myClient.available() > 0) { toggle = !toggle; if (toggle) { println("This version is BROKEN ...\n"); while (myClient.available() > 0) { // // This is the function that contains BUG 606 // dataString = myClient.readStringUntil('\n'); printString(dataString); } } else { println("This version works ...\n"); while (myClient.available() > 0) { // // This is a workaround for BUG 606 // len = myClient.readBytesUntil('\n',dataBytes); dataString = new String(dataBytes); dataString = dataString.substring(0,len); printString(dataString); } } } } void printString(String s) { if (dataString == null) { println("null string"); } else { print("data string = " + s); } }