We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Processing Server Client Question
Page Index Toggle Pages: 1
Processing Server Client Question (Read 262 times)
Processing Server Client Question
Mar 4th, 2008, 12:02am
 
Hi I'm new to processing, I do have a question that I cannot find anywhere.

Short: I am trying to write a Server/Client app. where the server would send 1 number to the client.  

Server: (code below)
import processing.net.*;
Server myServer;
int val = 1;

void setup() {
 size(200, 200);
 background(0);
 myServer = new Server(this, 5204);
}

void draw() {
 myServer.write(val);
}

On my client:
void setup() {
 size(200, 200);
 background(0);
 myClient = new Client(this, "127.0.0.1", 5204); //Localhost
}

void draw() {
  if (myClient.available() > 0) {
   myClient.read();
   println("-------------------------- I got something  --------------------------" + "                      " + myClient.read() + "       From:    " + myClient.ip() );
   mySecondReceivedNumber = myClient.read();
   println("second number: " + mySecondReceivedNumber + "   myClient.read:   " + myClient.read());
}

The problem is my client is receiving garbage data such as -1, 2, 0.   Can someone tell me why I get this data?
Page Index Toggle Pages: 1