This is about Java 'network' library

Hello @GWAK ,

Working example below that will receive data in the server sketch.

Server and client (start first)

// Server and client

import processing.net.*;

Server server0;
Client client0;

void setup() 
  {
  size(400, 200);
  server0 = new Server(this, 5204);  // Listen on port 5204
  println("Server started on port 5204");
  }

void draw() 
  {
  }

void serverEvent(Server server, Client client) 
  {
  println("New client connected: " + client.ip());
  server.write("Start sending...");
  }
  
void clientEvent(Client myClient) 
  {
  print("Client0 received:  ");
  String dataIn = myClient.readString();
  println(dataIn);
  }  

Client (start second)

// Client

import processing.net.*;

Client client1;
boolean sendData = false;

int count = 0;

void setup() 
  {
  size(200, 200);
  client1 = new Client(this, "127.0.0.1", 5204);
  }

void draw() 
  { 
  // Sends data every 60 frames
  if (sendData)
    {
    if (frameCount%60 == 0) // Every 1 sec at if frameRate = 60
      {
      println("Client1 sending: " + count);
      client1.write(str(count)); // Sends data to server
      count++;
      }
    }
  }

// Once the client connects to server it starts sending data
void clientEvent(Client myClient) 
  {
  print("Server Says:  ");
  String dataIn = myClient.readString();
  println(dataIn);
  
  if(dataIn.equals("Start sending..."))
    sendData = true;
  }

I used the console to show messages and data sent and received.
You will have to make each sketch active (click with mouse) to see updates (sending and receiving) in console.

You could also receive the data in draw():

// Server and client

import processing.net.*;

Server server0;
Client client0;

void setup() 
  {
  server0 = new Server(this, 5204);  // Listen on port 5204
  println("Server started on port 5204");
  }

void draw() 
  {
  // Get the next available client
  client0 = server0.available();
  
  if (client0 != null) 
    {
    println("Client connected: " + client0.ip());
        
    while (client0.available() > 0) 
      {
      // Read the data sent by the client1
      String msg = client0.readString(); 
        {
        println("Received: " + msg);
        }
      }
    }    
  }

void serverEvent(Server server, Client client) 
  {
  println("New client connected: " + client.ip());
  server.write("Start sending...");
  }
  
//void clientEvent(Client myClient) 
//  {
//  print("Client0 received:  ");
//  String dataIn = myClient.readString();
//  println(dataIn);
//  }  

I got a lot of insight from here:

Reference:

And the examples that come with Processing for the Network library.

And a lot of testing and troubleshooting!

Have fun!

:)

2 Likes