We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm trying to create an auto reconnect to a client. I am using the library already present, that net. when you try to instantiate a client and the server is not yet present, there is of course an exception error and everything stops. I have tried in various ways, but I can not control a specific exception, with the processing net library?. so ... How to do to have a client who tries to reconnect if a server is not yet present, or the connection is lost? thanks people.
Answers
The exception is just a println() from the library, it isn't really thrown to the sketch, so you cannot catch it. Processing rarely throws exceptions, in general, except when it exposes low level functions, precisely to allow finer control.
So, the only way to check if there is an error is to check the returned value, to see if it is null.
Can you elaborate on that? which value are we to look for as null?
even when the server is stopped, println(myclient) gives something like "processing.net.Client@21f33544" even on initial connect. there is an exception thrown, "java.net.ConnectException: Connection refusedjava.net.ConnectException: Connection refused". calling myclient = new Client(...) a 2nd time, once the server is running, still results in the same handle but a new exception "java.lang.NullPointerException". calling the stop() method first also does not seem to allow reconnecting. from the outside, it appears that there's a bug in the Client library where it is failing to release resources so that a re-connection is possible.
I have actually encountered the same problem when working on my project and I found the client.active() to be useful to check if the client is still connected the server or was able to find a connection.
I'm not really sure if this is a good way to handle these problems but it works for me.