Hi Guys,
I work with the processing library and would like to know if there are any servers before I write. The Problem: client.available doesn’t work before writing:
Server:
import processing.net.*;
Server myServer;
void setup() {
size(200, 200);
// Starts a myServer on port 5204
myServer = new Server(this, 5204);
}
void draw() {
Client c = myServer.available();
if(c != null)
background(c.read());
}
Client:
import processing.net.*;
Client myClient;
int dataIn;
int val = 0;
void setup() {
size(200, 200);
// Connect to the local machine at port 5204.
// This example will not run if you haven't
// previously started a server on this port.
myClient = new Client(this, "127.0.0.1", 5204);
}
void draw() {
val = (val + 1) % 255;
print(myClient.available());
myClient.write(val);
background(val);
}
I believe that the problem is on your Client IP code: myClient = new Client(this, "127.0.0.1", 5204);
Check your computer IP to match the network you are using or search what is my ip on Google and try substituing there.
Also, for future research you might find helpful the following links:
He provides a lot of information that I found useful myself.
I want to know if a server is available or not before i write to it as a client. It works before loading but not before sending. If the client is receiving information from the server it works, but not if the client is sending information.
Example (cleint receives Information):
import processing.net.*;
Server myServer;
int val = 0;
void setup() {
size(200, 200);
// Starts a myServer on port 5204
myServer = new Server(this, 5204);
}
void draw() {
val = (val + 1) % 255;
background(val);
myServer.write(val);
}
import processing.net.*;
Client myClient;
int dataIn;
void setup() {
size(200, 200);
// Connect to the local machine at port 5204.
// This example will not run if you haven't
// previously started a server on this port.
myClient = new Client(this, "127.0.0.1", 5204);
}
void draw() {
print(myClient.available());
dataIn = myClient.read();
background(dataIn);
}