|
Author |
Topic: carnivore question (Read 945 times) |
|
diriccio
|
Re: carnivore question
« Reply #1 on: Oct 13th, 2004, 9:18pm » |
|
is this post wrong here? hello?
|
|
|
|
fjen
|
Re: carnivore question
« Reply #2 on: Oct 14th, 2004, 3:01pm » |
|
no it's not ... you might wanna have carnivore run on a different thread ... although it will introduce some other problems it solves the speed thing (don't have carnivore ... so code's not checked): threads at sun: http://java.sun.com/docs/books/tutorial/essential/threads/ Code:// carnivore Socket socket; BufferedReader packetreader; String packet; int ln; carnivoreChecker carn; ball b1 = new ball(300,300); float targetX, targetY, targetR; void setup() { framerate(25); size(600, 400); textFont(loadFont("fonts/Univers45.vlw.gz"), 14); try { socket = new Socket("127.0.0.1", 6667); packetreader = new BufferedReader( new InputStreamReader(socket.getInputStream()) ); } catch(IOException e) { println(e); } carn = new carnivoreChecker(); carn.start(); } void loop(){ background(0,0,0); carn.draw(); b1.update(); } void mousePressed(){ b1.myX = ln; b1.myY = ln; } class carnivoreChecker extends Thread { public boolean running = false; carnivoreChecker(){ targetX = int(random(0, width)); targetY = int(random(0, height)); } public void start () { this.running = true; super.start(); } public void run () { while (running){ this.update(); try { sleep((long)(1000/25.0)); } // give system some air ... // catch (Exception e) {} //println("re-run carnivore"); } } void update(){ if (packetreader != null) { try { packet = packetreader.readLine(); //println("carnivore packet: " + packet); } catch(IOException e) { println(e);} //b1.myX = ln; } } void draw() { if (packet != "" && packet != null) { text("data from Carnivore", 10, 30); fill(50,50,50); text(packet, 10, 50); String list[] = splitStrings(packet); text(list[1], 10, 90); text(list[3], 10, 130); ln = packet.length(); text("packet size:",10,190); text(ln, 100, 190); } } public void quit() { this.running = false; super.stop(); } } class ball{ float myX, myY, distanceX,distanceY; int originX, originY; ball(int x,int y){ originX = 0; originY = 0; myX = x; myY = y; } void update(){ distanceX = originX-myX; distanceY = originY-myY; myX += distanceX/20; myY += distanceY/10; stroke(255); point (myX,myY); } } public void stop() { carn.quit(); } |
|
|
|
|
|
diriccio
|
Re: carnivore question
« Reply #3 on: Oct 15th, 2004, 12:54am » |
|
great! works for me at the moment. thanks for the link on threads as well!
|
|
|
|
|