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.
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();
}