Capturing Net Client Error if Server Not Running

Hello,

Try this:

Modified SharedCanvasClient
/**
 * 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:

:slight_smile:

1 Like