Hello folks,
This is more for the general community to add to the topic.
I was able to connect these two and communicate between them:
-
Server by @GWAK
This is about Java 'network' library - #8 by GWAK
I converted it to English first with ChatGPT or Gemini
It uses the Processing Network library:
import processing.net.;* -
Client by @jafal
This is about Java 'network' library - #14 by jafal
It uses the Java libraries:
import java.net.;*
import java.io.;*
I added this to client in draw() so it was sending data every 1 sec for a frameRate of 60:
// Counter using frameCount:
if(frameCount%60 == 0)
{
int counter = frameCount/60;
out.println(counter);
println("Sent to server: " + counter);
}
If you are running this code on a single PC try this with 2 different sketches for client with 2 different IPs:
-
Client Sketch 1
String serverIP = “192.168.213.1”; // Server IP of PC (This is my PC and will change on your computer). -
Client Sketch 2
String serverIP = “127.0.0.1”; // Server IP using localHost
Connecting these two clients to the server (with some delay) I was able to see the two connections and data received in Server console:
How cool is that!
There are different libraries used and some advanced topics.
Some research will provide clarity.
I found ChatGPT and Gemini useful for:
- Commenting\explaining code.
- It also made suggestions for consideration.
- Converting code from Processing only library to Java library and vice versa.
- Keep in mind that all ChatGPT code and responses should be scrutinized!
It may be incorrect and very apologetic for it. It is doing unsupervised training and self learning along the way and sometimes has incorrect answers.
Thanks @GWAK and @jafal for code provided.
The code provided looks like a solid implementation using familiar and widely adopted components and code which was adapted for the Processing environment.
It took a lot research on my part to sift through all the code and thoroughly understand the implementation.
It is important to provide context with code that is shared:
Guidelines—Answering Questions
Comments and references are important to provide context; I will have to discipline myself to do that and posted this to help others with the code provided. I sometimes look at my older code and have no idea what I was doing from lack of comments or references!
I certainly enjoyed the exploration of this but it may be a challenge for others.
Have fun! I learned a lot!
:)