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.
Page Index Toggle Pages: 1
cpu Problem (Read 850 times)
cpu Problem
Jan 22nd, 2010, 7:29am
 
I have Written a Chat client and a Chat Server and evrything works really god. But I have the problem that if I starts the server or the client the Java Process in the Taskmanager needs 50% of my Cpu power and I have two cpu's with 2,66 ghz and I have no idea why. Undecided
I would be very happy if someone could help me with this Problem. And Sory for my bad english I am German.

This is the Code for the Client.

String input;
String pinput;
String output;
String poutput [];
String client;
String clientsplit [];
String clientsplit2 [];
String ipp [];
int ippnr;
int stopper;
int delete;
int i;
int clientNr;
import processing.net.*;
Client myClient;

void setup(){
 size(800, 250);
 background(0);
 textFont(createFont("SanSerif", 16));
 myClient = new Client(this, "5.134.169.118", 5204);
 input = "";
 output = "";
 delay(200);
 poutput = new String [500];
 ipp = new String [500];
 ippnr = 1;
 stopper = 1;
 poutput [1] = "";
 delete = 0;
 client = "";
 while(clientNr == 0){
   if (myClient.available() > 0){
     delay(200);
     clientNr = myClient.read();
     delay(200);
     myClient.clear();
   }
   for(int b = 0; b < clientNr; b++){
     client += ",";  
   }
   clientsplit = split(client, ',');
   client = "±";
   client += clientsplit.length;

 }

}

void draw(){
 background(0);
 information_holen();
 text(input, 30, 50);
 text(output, 30, 100);
 text(hour(), 30, 200);
 text(minute(), 70, 200);
 text(second(), 110, 200);

}

void keyPressed(){
 if( key == ENTER ){
   if(output.equals("exit") == true){
     shut_down();
   }
   output += client;
   myClient.write(output);
   output = "";
   delete = 0;
 }
 if( key == 'a' || key == 'A' || key == 'b' || key == 'B' || key == 'c' || key == 'C' || key == 'D' || key == 'd' || key == 'e' || key == 'E' || key == 'f' || key == 'F' || key == 'g' || key == 'G' || key == 'h' || key == 'H' || key == 'i' || key == 'I' || key == 'j' || key == 'J' || key == 'K' || key == 'k' || key == 'l' || key == 'L' || key == 'm' || key == 'M' || key == 'n' || key == 'N' || key == 'O' || key == 'o' || key == 'p' || key == 'P' || key == 'q' || key == 'Q' || key == 'r' || key == 'R' || key == 's' || key == 'S' || key == 't' || key == 'T' || key == 'u' || key == 'U' || key == 'V' || key == 'v' || key == 'w' || key == 'W' || key == 'x' || key == 'X' || key == 'y' || key == 'Y' || key == 'z' || key == 'Z' || key == 'ö' || key == 'Ö' || key == 'ä' || key == 'Ä' || key == 'ü' || key == 'Ü' || key == '1' || key == '2' || key == '3' || key == '4' || key == '5' || key == '6' || key == '7' || key == '8' || key == '9' || key == '0' || key == '^' || key == '°' || key == '!' || key == '"' || key == '§' || key == '$' || key == '%' || key == '&' || key == '/' || key == '(' || key == ')' || key == '=' || key == '?' || key == '´' || key == '²' || key == '³' || key == '{' || key == '[' || key == ']' || key == '}' || key == '\\' || key == '\'' || key == '´' || key == '+' || key == '*' || key == '~' || key == '#' || key == '\'' || key == '-' || key == '_' || key == '.' || key == ':' || key == ',' || key == ';' || key == 'µ' || key == '€' || key == '@' || key == '|' || key == '<' || key == '>' || key == ' ' || key == 'ß' || key == '`'){
   delete++;
   poutput [delete] = output;
   output += key;
 }
 if( key == BACKSPACE || key == DELETE){
   output = poutput [delete];
   if(delete >= 2){
     delete = delete - 1;
   }
 }
 if( key == CODED){
 if( keyCode == UP){
   if( ippnr >=2){
 ippnr = (ippnr-1);
 input = ipp [ippnr];
   }
 }
 if( keyCode == DOWN){
   if( ippnr <= (stopper-2)){
 ippnr++;
 input = ipp [ippnr];
   }
 }
 }

}



void information_holen(){
 if (myClient.available() != 0) {
   println("hallo");
   pinput = input;
   input = myClient.readString();
   myClient.clear();
   clientsplit2 = split(input, '±');
   input = clientsplit2[0];

   if(clientsplit2.length == 2){


     int l2 = client.length();
     char l22;
     String l2s = "";
     int b = 1;

     for(int g = 0; g < (l2-1); g++){

       l22 = client.charAt(b);
       println(client.charAt(b));
       l2s += l22;
       b++;

     }

     if(clientsplit2[1].equals(l2s) == true){
       input = pinput;
     }
   }
   ipp [stopper] = input;
   ippnr++;
   stopper++;
 }
}
void shut_down(){
 delay(1000);
 myClient.stop();
 exit();
}
Re: cpu Problem
Reply #1 - Jan 22nd, 2010, 7:31am
 
And this is the code of the Server:

import processing.net.*;
Server myServer;
String output ;
String input ;
String poutput [];
int delete;
int Serveran = 0;
int client;
int clientnr = 0;


void setup()
{
 size(600, 250);


 myServer =new Server(this, 5204);
 fill(0);
 output = "Server gestarted";
 input = "";
 textFont(createFont("SanSerif", 20));
 poutput = new String [100];
 poutput [1] = "";
 delete = 0;
 myServer.write(output);
 client = 1;

}

void draw()
{
 Client myClient = myServer.available();
 if (myClient !=null) {
   input = myClient.readString();
   myServer.write(input);
   myClient = null;
 }
 background(255);
 println(output);
 text(input, 30, 50);
 text(output, 30, 100);
 text("Verbundene Clients: "+clientnr, 30, 150);
 text(hour(), 30, height-50);
 text(minute(), 70, height-50);
 text(second(), 110, height-50);
 println(client);

}

void keyPressed(){
 if( key == ENTER ){
   if(output.equals("exit") == true){

     exit();
   }
   myServer.write(output);
   output = "";
   delete = 0;
 }
 if( key != ENTER && key != BACKSPACE && key != DELETE){
   delete++;
   poutput [delete] = output;
   output += key;
 }
 if( key == BACKSPACE || key == DELETE){
   output = poutput [delete];
   if(delete >= 2){
     delete = delete - 1;

   }

 }
}

void serverEvent(Server someServer, Client someClient) {

 myServer.write(client);
 client ++;
 clientnr ++;


}
Re: cpu Problem
Reply #2 - Jan 22nd, 2010, 12:42pm
 
Processing will attempt to run the draw() method at 60fps and the code in your draw method looks quite demanding. You can find out the framerate of your application with
Code:
println(framerate); 


inside the draw() method

You might try changing the framerate to something lower e.g. in setup()
Code:
frameRate(10); 


Re: cpu Problem
Reply #3 - Jan 24th, 2010, 9:55am
 
The Frame Rate is something around 9,5 so it doesent help if i put it up to 10.
Perhaps someone can say me how I can make the code easyer for the computer.
But thank you for the god Idea. Smiley
Page Index Toggle Pages: 1