# Capturing Net Client Error if Server Not Running

**URL:** <https://discourse.processing.org/t/capturing-net-client-error-if-server-not-running/17536>\
**Category:** Libraries\
**Created:** [February 4, 2020, 1:53am UTC](https://discourse.processing.org/t/capturing-net-client-error-if-server-not-running/17536 "2020-02-04T01:53:58Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [February 7, 2020, 12:56am UTC](https://discourse.processing.org/t/capturing-net-client-error-if-server-not-running/17536/6 "2020-02-07T00:56:17Z")

</div>

Hello,

Try this:

> **Modified SharedCanvasClient**
>
> ```auto
> /**
> * Shared Drawing Canvas (Client) 
> * by Alexander R. Galloway. 
> * 
> * The Processing Client class is instantiated by specifying a remote 
> * address and port number to which the socket connection should be made. 
> * Once the connection is made, the client may read (or write) data to the server.
> * Before running this program, start the Shared Drawing Canvas (Server) program.
> */
> 
> import processing.net.*;
> 
> Client c;
> String input;
> int data[];
> 
> boolean clientConnected = false;
> 
> void setup() 
> {
> size(450, 255);
> background(204);
> stroke(0);
> frameRate(5); // Slow it down a little
> // Connect to the server's IP address and port
> while(!clientConnected)
> {
> c = new Client(this, "127.0.0.1", 12345); // Replace with your server's IP and port
> if(!c.active())
> {
> println("Not connected to server");
> println("Start the server");
> clientConnected = false;
>       
> }
> else
> {
> println("Connected to server");
> clientConnected = true;
> }
> }
> }
> 
> void draw() 
> {
> if (clientConnected)
> {
> // Do something  
> }
> else
> {
> // Do something else
> }
> }
> 
> ```

See this topic:

> [@Exception handling in processing.net.\* -- why can't I catch exceptions?](https://discourse.processing.org/t/exception-handling-in-processing-net-why-cant-i-catch-exceptions/12192):
>
> 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](http://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 cau…

’ 🙂 ’

---

_[View the full topic](https://discourse.processing.org/t/capturing-net-client-error-if-server-not-running/17536)._
