In my project I need to make a socket connection, however I realized that there is a chance that the user will not start the server. When this happens, it is obvious that the client will not be able to connect to the server. I wanted my application to be able to handle this exception. However, it seems that processing is unable to “catch” the exception.
my code:
try {
myClient = new Client(this, "127.0.0.1", 8000);
} catch (Exception e) {
//print(e);
print("I stopped by to say hi!!!");
exit();
}
what the processing terminal returns is this:
java.net.ConnectException: Conexão recusada (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at processing.net.Client.<init>(Unknown Source)
at INSHRDLU.setup(INSHRDLU.java:25)
at processing.core.PApplet.handleDraw(PApplet.java:2432)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1547)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)
My question is:
What am I doing wrong?