Processing Network Client.available();

I want to know if a server is available or not before i write to it as a client. It works before loading but not before sending. If the client is receiving information from the server it works, but not if the client is sending information.

Example (cleint receives Information):


import processing.net.*;

Server myServer;
int val = 0;

void setup() {
  size(200, 200);
  // Starts a myServer on port 5204
  myServer = new Server(this, 5204); 
}

void draw() {
  val = (val + 1) % 255;
  background(val);
  myServer.write(val);
}

	

import processing.net.*; 

Client myClient; 
int dataIn; 
 
void setup() { 
  size(200, 200); 
  // Connect to the local machine at port 5204.
  // This example will not run if you haven't
  // previously started a server on this port.
  myClient = new Client(this, "127.0.0.1", 5204); 
} 
 
void draw() { 
  print(myClient.available());
  dataIn = myClient.read(); 
  background(dataIn); 
}