We are about to switch to a new forum software. Until then we have removed the registration on this forum.
First off, this is my first post here, so I apologize in advance for any mistakes I may have made.
So I've been working on setting up a Client/Server system, and I'm trying to get them to send Strings to each other. However, I was running into a very strange issue: whenever I set some variable equal to readString(), the program seems unable to recognize it as a string. After toying around with it for a while, I wrote a minimalist code to demonstrate the source of my confusion...
First, the Server code:
import processing.net.*;
Server server;
void setup() {
size(600,400);
server = new Server(this, 5204);
}
void draw(){
Client client = server.available();
if (client != null) {
String msg = client.readString();
println(msg);
println(msg == "k");
}
}
Next, the Client code:
import processing.net.*;
Client client;
void setup() {
size(400, 200);
client = new Client(this, "127.0.0.1", 5204); //I replaced 127.0.0.1 with my IP address in the actual code
}
void draw() {
}
void mouseClicked(){
client.write("k");
}
I would have expected it to return "k", then "true", but it returns "k", then "false". Is readString() not actually a string or something? What's going on?
Any and all help would be appreciated.
Answers
...And if it matters, I'm running Processing 2.2.1 on a Mac (version 10.9.5).
try msg.equals("k") instead of msg == "k"
Please check https://processing.org/reference/equality.html
Kf
Thanks so much for the help! Everything is running as intended now.