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 & HelpOther Libraries › how to readStringUntil
Page Index Toggle Pages: 1
how to readStringUntil (Read 829 times)
how to readStringUntil
Nov 27th, 2006, 4:11am
 
so i wrote a really simple client and server, where the client sends an integer string followed by a semicolon, and the server reads the integer string followed by a semicolon and writes it to all clients.

unfortunately, not all of the strings seem to make it from the client to the server.  what is going on?

here is my simple server code:

import processing.net.*;

int server_port = 5204;      
Server server;        
char data_delimiter = ';';

Client client;
String client_data;

void setup()
{
 size(100, 100);
 background(0);
 frameRate(30);
 
 server = new Server(this, server_port);  
}

void draw()
{
 background(0);
   
 //get next available client
 client = server.available();
 
 // send client data to all clients
 if (client != null)
 {
   client_data = client.readStringUntil(data_delimiter);        
   if (client_data != null)
   {      
     println(client_data);
     server.write(client_data);
   }    
 }
}

and here is my simple client code:

import processing.net.*;

Client client;
String server_address = "127.0.0.1";
int server_port = 5204;

int msg_count;
char data_delimiter = ';';

boolean send_msg;

void setup()
{
 size(100,100);
 client = new Client(this, server_address, server_port);
 msg_count = 0;
 send_msg = true;
}

void draw()
{
 String client_data;
   
 if (client.available() > 0)
 {
   client_data = client.readStringUntil(data_delimiter);
  // println("received: " + client_data);
 }
 
 if (send_msg)
 {

   client.write(Integer.toString(msg_count) + data_delimiter);
   println("sent: " + msg_count + data_delimiter);
   msg_count++;
 }
}

void mouseReleased()
{
 send_msg = !send_msg;
}


what is going wrong?

Page Index Toggle Pages: 1