GWAK
1
import processing.net.*;
int port = 10002;
Server myServer;
long COUNT_NUM = 0;
void setup()
{
size(400, 400);
background(0);
myServer = new Server(this, port);
}
void draw() {
background(255);
delay(10000);
}
void serverEvent(Server someServer, Client someClient) {
COUNT_NUM++;
Client thisClient = myServer.available();
if (thisClient !=null) {
String whatClientSaid = thisClient.readString();
if (whatClientSaid != null) {
println(" COUNT : " + str(COUNT_NUM) +" / " + whatClientSaid);
}
}
}
âserverEventâ operates within the time of performing the delay in âdraw()â.
What is the principle?
Is it a thread?
And how do you do this? Can it be implemented through threads?
Yes, serverEvent() is called back by Serverâs thread.
1 Like
GWAK
3
Dear @GoToLoop
Canât we make it likeâserverEventâ?
There is a delay inâdraw()â when loading photo data, etc., or doing something. At this time,
When sending data processing to the thread, it seems that theâdelayâ ofâdraw()â will be resolved.
Is there any good way or example?
glv
5
Hello,
I am only sharing partial codeâŚ
Visual Example on YouTube:
Arduino to Processing Server to Processing Client
- Arduino is sending data to Processing Server.
- Processing Server is only receiving data from Arduino and sending to Processing Client.
draw() is not looping; see noLoop() in setup().
Processing Client Code
import processing.serial.*;
Serial myPort;
String sRx;
import processing.net.*;
Server s;
String input;
void setup()
{
size(200, 200);
background(0);
s = new Server(this, 12345);
printArray(Serial.list());
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 19200);
myPort.bufferUntil(' ');
frameRate(60);
noLoop();
}
void draw()
{
// println(sRx);
}
void serialEvent(Serial myPort)
{
sRx = myPort.readString();
s.write(sRx);
// println(sRx);
}
- Processing Client is receiving data and buffer it into an array and updates canvas every draw() cycle (60fps default).
References:
Examples that come with Processing:
:)