Hello,
I've already written as you suggest, but Client class doesn't throw an exception. Indeed, the application freezes for a few seconds and afterwards I get an answer at the command prompt showing that there is no connection to the webserver.
This is my code (just a modification of the Client class example):
I would like:
1) Avoid that my application freezes while waiting for an answer;
2) Adjust the connection time to any value;
3) Let the application know that there is a connection problem.
Thanks in advance!
SAM
I've already written as you suggest, but Client class doesn't throw an exception. Indeed, the application freezes for a few seconds and afterwards I get an answer at the command prompt showing that there is no connection to the webserver.
This is my code (just a modification of the Client class example):
- /**
* 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.
*/
import processing.net.*;
// import processing.xml.*;
XML xml;
Client c;
String data;
void setup() {
size(200, 200);
background(50);
fill(200);
try {
c = new Client(this, "192.168.1.41", 8081); // Connect to server on port 8081
}
catch(Exception e) {
// an exception was thrown so decide what to do with it
String className = e.getClass().getSimpleName();
println("Name of exception class: " + className);
println("Not available");
}
}
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);
}
}
- java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:189)
at processing.net.Client.<init>(Client.java:77)
at prova2.setup(prova2.java:45)
at processing.core.PApplet.handleDraw(PApplet.java:2241)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
at processing.core.PApplet.run(PApplet.java:2140)
at java.lang.Thread.run(Thread.java:662)
1) Avoid that my application freezes while waiting for an answer;
2) Adjust the connection time to any value;
3) Let the application know that there is a connection problem.
Thanks in advance!
SAM