How can we run two programs simultaneously in Processing with one sending data to another?

I want to send json data file from one program to another program with both running simultaneously.
Is it possible in processing?

1 Like

Hi @Ruchi. Yes this is quite a common scenario for Processing. Assuming both applications are written with Processing or Java then you will want to look at the: loadJSONObject / Processing.org and the write option: saveJSONObject / Processing.org

There are a lot of other options for input and output depending on how you are reading and/or writing the data in the documentation here: Input / Processing.org and here: Output / Processing.org

The only trick is the scheduling of reading and writing as not to corrupt the data on one end. For example, making sure data is written before it is read. There are a lot of ways to handle this, it just depends on what you are trying to accomplish.

1 Like

Hi! From what you are suggesting, it would all come in one program right? But what if the program is too big to include everything in one file & for the sake of simplicity, I want to create two separate programs one creating JSON file & other using it. Could that be done in sequence?

Yes, absolutely. What you’re trying to do is fairly common as far as a technical task. One program writes the data, the other reads it.

What I mentioned previously is that the reading program doesn’t know necessarily when the writing program is finished, therefore, it is possible without careful handling, that you could read old or corrupted data. This becomes especially tenuous when you are trying to read and write asynchronously.

I don’t know if Processing or Java can tell you if a file is being written to. Most operating systems allow files to be written to and read from at the same time, kind of like circular buffers, but the programmer has to know what they’re doing as to not read data that has not been written.

So you probably need some sort of inter-application communication to tell the reader application it is ok to read and the writer application it is ok to write. I can think of several ways of doing this. You can do it manually, just click a button to read or write in each respective program. But if that is not acceptable you would need some sort of local network communication. I have used OSC before ( oscP5 (sojamo.de)) to talk between applications, but the Processing network library should also be able to suffice: Network / Libraries / Processing.org.

1 Like

I’m not aware if anyone can run two programmes at a go what I know is that you can make Hardware communicate with a software and vice versa. It is possible in web development, in this case you will make the front end communicate with the backend.

You can also load and animate a json file. All the best with your project.

2 Likes