Loading...
Logo
Processing Forum
I got always after 1-2 minutes the same errorcode and just the client crashes. The Compiler marks always the line 94

I rly dont know why. Here is my code for the client and server: 

Copy code
  1. //Server

  2. import processing.net.*;
  3. Server myServer;
  4. Client myClient; 
  5. String input;
  6. float data[];
  7. int val = 0;
  8. int rad = 20;        // Width of the shape
  9. float xpos, ypos;    // Starting position of shape    

  10. float xspeed = 5.6;  // Speed of the shape
  11. float yspeed = 4.4;  // Speed of the shape

  12. int xdirection = 1;  // Left or Right
  13. int ydirection = 1;  // Top to Bottom

  14. void setup() {
  15.   size(600, 400);
  16.    noStroke();
  17.   frameRate(30);
  18.   ellipseMode(RADIUS);
  19.   // Set the starting position of the shape
  20.   xpos = width/2;
  21.   ypos = height/2;
  22.   myServer = new Server(this, 9000); 
  23. }

  24. void draw() {
  25.  background(102);

  26.   // Update the position of the shape
  27.   xpos = xpos + ( xspeed * xdirection );
  28.   ypos = ypos + ( yspeed * ydirection );
  29.   
  30.   // Test to see if the shape exceeds the boundaries of the screen
  31.   // If it does, reverse its direction by multiplying by -1
  32.   if (xpos > width-rad || xpos < rad) {
  33.     xdirection *= -1;
  34.   }
  35.   if (ypos > height-rad || ypos < rad) {
  36.     ydirection *= -1;
  37.   }
  38.   // Draw the shape
  39.   ellipse(xpos, ypos, rad, rad);
  40.   myServer.write(xpos + " " + ypos + " " + rad + " " + rad + "\n");
  41.  
  42.   myClient = myServer.available();
  43.   if (myClient != null) {
  44.   input = myClient.readString();
  45.   data = float(split(input,' '));
  46.   print(input);
  47.   }
  48. }


  49. //Client
  50. import processing.net.*; 
  51. Client myClient; 
  52. int dataIn; 
  53.  String input;
  54. float data[];
  55. void setup() { 
  56.   size(600, 400); 
  57. noStroke();
  58.   frameRate(30);
  59.     ellipseMode(RADIUS);


  60.   myClient = new Client(this, "127.0.0.1", 9000); 
  61.  
  62. void draw() { 
  63.   background(102);
  64. if (mousePressed == true) {
  65.     // Draw our line
  66.     stroke(255);
  67.     line(pmouseX, pmouseY, mouseX, mouseY);
  68.     // Send mouse coords to other person
  69.     myClient.write(pmouseX + " " + pmouseY + " " + mouseX + " " + mouseY + "\n");
  70. }
  71.   if (myClient.available() > 0) { 
  72. input = myClient.readString();



  73.   input = input.substring(0, input.indexOf("\n")); // Only up to the newline


  74.     data = float(split(input,' ')); // Split values into an array
  75.    
  76.   
  77.     ellipse(data[0], data[1], data[2], data[3]);
  78.     print(input);
  79.     
  80.   } 

Replies(5)



probably in this case the var input is empty after line 88 and so data is empty

Check in line 94 whether data.length is >1

Copy code
  1. if (data.length > 1) {
  2.     ellipse(data[0], data[1], data[2], data[3]);
  3.     print("OK with " + input);
  4. }
  5. else
  6. {
  7.     print("empty with "+input+"<");
  8. }

instead just draw the old ellipse

Greetings, Chrisir    

If you need an answer, please send me a personal message since this forum doesn't notify.
i have anyways the same errorcode .... can you pls help me ? :(
Whenever something comes from an external source, be it a user input, a file, a URL, etc.,
always diligently parse that input whether it's in the format your code would expect it to be.

That is so b/c you don't have control over them.
Moreover, malicious attacks can try sending to your program a corrupt input
in order to crash and even take control of it! 

In your case, in order to draw an ellipse(), you need at least 4 elements from an Array.
So, you gotta refuse any Array w/ less than 4 elements in it!

if (data.length >= 4)      ellipse(data[0], data[1], data[2], data[3]);

okay i try this version :  if (data.length >= 4) 

no errors anymore. i will test it these days  with my main pong game

thx to you both :) im rly happy
glad to hear................