Created
July 30, 2020 03:00
-
-
Save TrevCan/5abc313a1c45c90410139acde122f0e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2B: Shared drawing canvas (Client) | |
import processing.net.*; | |
Client c; | |
String input; | |
int data[]; | |
void setup() { | |
size(450, 255); | |
background(204); | |
stroke(0); | |
frameRate(25); // Slow it down a little | |
// Connect to the server’s IP address and port | |
c = new Client(this, "192.168.1.136", 12345); // Replace with your server’s IP and port | |
} | |
void draw() { | |
if (mousePressed == true) { | |
// Draw our line | |
stroke(255); | |
line(pmouseX, pmouseY, mouseX, mouseY); | |
// Send mouse coords to other person | |
c.write(pmouseX + " " + pmouseY + " " + mouseX + " " + mouseY + "\n"); | |
} | |
// Receive data from server | |
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 | |
// Draw line using received coords | |
stroke(0); | |
line(data[0], data[1], data[2], data[3]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2A: Shared drawing canvas (Server) | |
import processing.net.*; | |
Server s; | |
Client c; | |
String input; | |
int data[]; | |
void setup() { | |
size(450, 255); | |
background(204); | |
stroke(0); | |
frameRate(25); // Slow it down a little | |
s = new Server(this, 12345); // Start a simple server on a port | |
} | |
void draw() { | |
if (mousePressed == true) { | |
//println(Server.ip()); | |
// Draw our line | |
stroke(255); | |
line(pmouseX, pmouseY, mouseX, mouseY); | |
// Send mouse coords to other person | |
s.write(pmouseX + " " + pmouseY + " " + mouseX + " " + mouseY + "\n"); | |
} | |
// Receive data from client | |
c = s.available(); | |
if (c != null) { | |
input = c.readString(); | |
input = input.substring(0, input.indexOf("\n")); // Only up to the newline | |
data = int(split(input, ' ')); // Split values into an array | |
// Draw line using received coords | |
stroke(0); | |
line(data[0], data[1], data[2], data[3]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment