Skip to content

Commit cb25fa6

Browse files
committed
Fix drawings of other clients not showing in example 19-7
A client would only show it's own drawings, but not what other connected clients were drawing. This likely didn't work in Processing 3 because the drawing calls were made outside of the main animation thread. They are now made inside of the main draw() loop which let's everyone see what everyone else is drawing (with a slight network delay).
1 parent 2a9ee79 commit cb25fa6

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

chp19_data_streams/example_19_07_multiuser_client/example_19_07_multiuser_client.pde

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import processing.net.*;
99
// Declare a client
1010
Client client;
11+
// Store mouse X/Y in this array
12+
int[] vals = new int[2];
1113

1214
void setup() {
1315
size(200, 200);
@@ -17,6 +19,10 @@ void setup() {
1719
}
1820

1921
void draw() {
22+
// Render an ellipse based on the current values
23+
fill(0, 100);
24+
noStroke();
25+
ellipse(vals[0], vals[1], 16, 16);
2026
}
2127

2228
// If there is information available to read from the Server
@@ -27,22 +33,15 @@ void clientEvent(Client client) {
2733
// Print message received
2834
println( "Receiving:" + in);
2935
// The client reads messages from the Server and parses them with splitTokens() according to our protocol.
30-
int[] vals = int(splitTokens(in, ",\n"));
31-
32-
// Render an ellipse based on those values
33-
fill(0, 100);
34-
noStroke();
35-
ellipse(vals[0], vals[1], 16, 16);
36+
vals = int(splitTokens(in, ",\n"));
3637
}
3738
}
3839

3940
// Send data whenever the user drags the mouse
4041
void mouseDragged() {
4142
// Put the String together with our protocol: mouseX comma mouseY newline
4243
String out = mouseX + "," + mouseY + "\n" ;
43-
fill(0, 100);
44-
noStroke();
45-
ellipse(mouseX, mouseY, 16, 16); // A message is sent whenever the mouse is dragged. Note that a client will receive its own messages! Nothing is drawn here!
44+
// A message is sent whenever the mouse is dragged. Note that a client will receive its own messages! Nothing is drawn here!
4645
client.write(out);
4746
// Print a message indicating we have sent data
4847
println("Sending: " + out);

0 commit comments

Comments
 (0)