サーバ側のプログラム
import processing.net.*;
Server s;
Client c, c0;
String input;
int data[];
void setup(){
size(450, 255);
background(204);
stroke(0);
frameRate(5); // Slow it down a little
// Connect to the server's IP address and port
c0 = new Client( this, "172.31.23.5", 54321 );
c0.write( "Spbl2020" );
while( c0.available() == 0 ){
delay( 100 );
}
String x = c0.readString();
c0.stop();
s = new Server( this, 56789 );
}
void draw(){
if (mousePressed == true) {
// 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
print( data[0]+" "+data[1] );
// Draw line using received coords
stroke(0);
line(data[0], data[1], data[2], data[3]);
}
}