# Calling processing sketches within a processing sketch

**URL:** <https://discourse.processing.org/t/calling-processing-sketches-within-a-processing-sketch/27167>\
**Category:** Libraries\
**Created:** [January 18, 2021, 6:04pm UTC](https://discourse.processing.org/t/calling-processing-sketches-within-a-processing-sketch/27167 "2021-01-18T18:04:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackeddielove](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@jackeddielove](https://discourse.processing.org/u/jackeddielove)\
**Post date:** [January 18, 2021, 6:04pm UTC](https://discourse.processing.org/t/calling-processing-sketches-within-a-processing-sketch/27167/1 "2021-01-18T18:04:30Z")

</div>

My processing code is getting very long. I’m essentially building a slideshow. Is it possible to build each slide individually and then call each one in the main program?  
This is the kind of thing I did when writing my dissertation in LaTeX. I wrote each chapter individually, and then called each one in the main program. So that’s the kind of solution I am hoping for.

---

<div class="post-metadata">

**Author:** ![NumericPrime](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/numericprime/32/16318_2.png) [@NumericPrime](https://discourse.processing.org/u/NumericPrime)\
**Post date:** [January 18, 2021, 8:03pm UTC](https://discourse.processing.org/t/calling-processing-sketches-within-a-processing-sketch/27167/2 "2021-01-18T20:03:27Z")

</div>

You can create two seperate sketches that communicate with each other via server.

Server

```auto
 import processing.net.*;

Server s;
Client c;
int data_alt[]={9, 9};
String input;
int data[];
int z=1;
int feld[][]={{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
int sending=0;

void setup() 
{
  size(600, 600);
  // background(204);
  fill(0);
  stroke(0);
  frameRate(20); // Slow it down a little
  s = new Server(this, 12360); // Start a simple server on a port
}

void draw() 
{    
  //send
  s.write("insert_variables_here"+"\n");

  //recieve
  c = s.available();
  if (c != null) {
    input = c.readString();
    input = input.substring(0, input.indexOf("\n")); // Only up to the newline
    println(input);
    data = int(split(input, ' ')); // Split values into an array
  }
}

```

Client

```auto
import processing.net.*;

Client c;
String input;
int[] data;
void setup() 
{
  c = new Client(this, ".....", 12360); // Replace with your server's IP and port
}

void draw() 
{
}
void gain() {
  c.write("Insert_variable_here");
  if (c.available() > 0) {
    input = c.readString();
    input = input.substring(0, input.indexOf("\n")); // Only up to the newline
    data = int(split(input, ' ')); // Split values into an array
  }
}

```

---

<div class="post-metadata">

**Author:** ![jackeddielove](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@jackeddielove](https://discourse.processing.org/u/jackeddielove)\
**Post date:** [January 18, 2021, 8:41pm UTC](https://discourse.processing.org/t/calling-processing-sketches-within-a-processing-sketch/27167/3 "2021-01-18T20:41:48Z")

</div>

Thank you, this looks like just what I need. I’m not super familiar with terms like server, IP, and port, but I think this will help me understand once I dig into it.  
Thank you very much for your help.
