readString Weirdness (Client/Server)

edited November 2017 in Library Questions

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

Sign In or Register to comment.