ME: Computer science professor. Reasonably adept at processing, though not a guru.
GOAL: To handle the exception in the code below, because I figure this is something my students will run into:
import processing.net.*;
Client myClient;
void setup() {
size(400, 400);
try {
myClient = new Client(this, “192.168.2.2”, 5025);
}
catch (Exception e) {
println(“Looks like server isn’t running”);
}
}
When I run the code above without a server for it to connect to, the exception is not caught. Instead, a java.net.ConnectException is raised with various diagnostic info in the console window. I have some suspicion this relates to Java and threads, but I bet there are people here who know more. Bottom line: Is this problem fixable within Processing? If not, I suspect the benefits are not worth the costs for my smart but beginner students, so I won’t bother. Still curious though as to what exactly is going on and what the fix might be.
I have been using the SharedCanvasClient and SharedCavasServer to test this.
if (c.active() == false)
{
println("Client not Connected");
clientFlag = false;
}
Processing still displays all the “gobbledygook” about what happened if you can’t connect to server but you can still proceed and use the clientFlag as you wish; I used it so I would not use any of the client methods for now. I may try reconnecting to server in future exploration of this.