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...
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
I'm writing a little program whose purpose is to fetch images from twitter, and which should be very simple, I think. Yet, I'm not very experienced with programming, so its giving me a headache, and I'm getting tired now.
I have a few problems here and there, but the first thing I want to ask is about loading URLs from twitter images, like this one: t.co/mAtQ0Q8cot. It works if you open it from the browser, but if I try to fetch its code using loadStrings or Client.write I get "The file "t.co/mAtQ0Q8cot" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable." or "java.net.UnknownHostException: t.co/mAtQ0Q8cot ...."
I want to read the content of the URL as text, and also be able to handle the exception if the content disappears or if it get a badly formatted web adress.
Here is my code for this part (three different versions I have tried to extract the HTML text):
import processing.net.*;
void setup() {
loadstrings3(); //<- Here I change the number accordingly. }
void loadstrings1() {
String[] html = new String[0]; html = loadStrings("t.co/mAtQ0Q8cot");
if (html == null) { println("Valor Nulo"); html = new String[2]; html[0] = "an"; html[1] = "error"; } else { println("html: " + html); } }
void loadstrings2() {
try { String[] html = loadStrings("t.co/mAtQ0Q8cot"); println("html: " + html); } catch (Exception e) { //<- This doesn't work at all... println("Exception e"); String[] html = new String[0]; html[0] = "an"; html[1] = "error"; }
}
void loadstrings3() { String html; Client c = new Client(this, "t.co/mAtQ0Q8cot", 80); c.write("GET / HTTP/1.0\r\n"); // Use the HTTP "GET" command to ask for a Web page c.write("\r\n");
if (c.available() > 0) { // If there's incoming data from the client... html = c.readString(); // ...then grab it and print it println(html); }
}
Also, how long should I wait before asking for another URL? Since if I hit the server too often (I intend to download like a 1000 of these URLs and pics XD) it won't work right?
Thanks!
---
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
Because I get confused very easily when trying to go back to the places where I've used them and because that way I'd instantly know if I'm writing their name properly.
---
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
I want to move a set of particles trough a sort of maze ( transparent 2D water pipes would be more like it). If one of them impacts the walls it dissapears. Any kind of help for this?
Oh, and mmm ... probably I should mention I'm a complete beginner and kind of remember the basics of high school math. :P
I'm kind of new to programming and I want to know of good resources (like books or websites) for planning a program and theoretical things I should know about methodology and the foundations of programming. Not the most fundamental things, as that would mean many hours of study, but something beyond the explanation of what objects and classes are that you see in every introduction to programming.
Some good tutorial or book about properly using flow charts for example (actually this is something I'm specifically looking for), or about things to keep in mind about memory when programming in Processing.