server and client
in
Core Library Questions
•
1 year ago
Hello,
I am trying to have the server make calculations based on the client's input.
How does the server read data from the client? Note, that there is a function for the client to read data
from the server:
int dataIn = myClient.read();
client code:
import processing.net.*;
Client myClient;
int dataIn;
void setup() {
size(200, 200);
myClient = new Client(this, "127.0.0.1", 504);
myClient.write("Hi there");
println(myClient.ip());
}
void draw() {
if (myClient.available() > 0) {
dataIn = myClient.read();
}
println("calculation from server: " + dataIn);
println("from client: mouse x= " + mouseX + " mouse y= " + mouseY);
myClient.write(mouseX);
}
server code:
import processing.net.*;
Server myServer;
int val = 0;
int dataIn;
void setup() {
size(200, 200);
myServer = new Server(this, 504);
}
void draw() {
println("mouse x from client = " + dataIn);
println("from server: mouse x= " + mouseX + " mouse y= " + mouseY);
myServer.write(mouseX);
int num = mouseX*10;
myServer.write(num);
}
1