FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   carnivore packet searching
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: carnivore packet searching  (Read 270 times)
ian

WWW
carnivore packet searching
« on: Oct 10th, 2003, 4:35am »

hello - i'm working on a simple carnivore client using processing. so far i've gotten it to connect to the right port, sign in on the 'carnivore channel' and start sending packets back. i was sending all the packet data to 'println' and it looked like I was getting what I want.  
 
Now I want to be able to find specific words in those packets. Right now I have a method that gets called every time a new packet comes through. I think they're coming in so fast though that the method is being refreshed before it has a chance to find the term i'm looking for.
 
I'm supposing I could either create a buffer for the packets, or somehow thread the method that does the search. Right now my code is as follows:
 
 
 
char k;
String data[];
String initstring;
int i;
BFont f;
 
void setup()
{
 
beginNet("localhost", 6667);  
joinchannel();
 
size(400, 400);
background(0);
stroke(153, 153, 0);
 
f = loadFont("Meta-Bold.vlw.gz");
 
textFont(f, 30);
 
}
 
 
public void netEvent()  
{  
  if (net != null)  
  {  
    data = splitStrings(net, ' ');  // Split and parse the data received in net  
    searchstring();
  }  
}  
 
void loop()
{
}
 
public void joinchannel()
{
initstring = "JOIN #carnivore";
netWrite(initstring);  
}
   
 
 
public void searchstring()
{
 for (i = 0; i < data.length; i++)  
    {  
    String instream = data[i];
     
    if (instream == "water")  
    {
    text(instream, 20, 10);
    }  
   
     
    }
}
   
void keyPressed()  
{  
  if (key >= 0x20 && key <= 0x7e)  
  {  
    endNet();
  }  
}  
 
Suffice it to say that it's not finding the word 'water'. I'm a bit new to all this - will processing let me thread it? Many thanks.  
 
ian
 
 
 
toxi

WWW
Re: carnivore packet searching
« Reply #1 on: Oct 10th, 2003, 12:42pm »

hey ian, you should read the technote about packet sniffing
 
as for speeding up the search for strings in a packet, you can avoid the time consuming splitStrings() by using the indexOf() function...
 
Code:
public void netEvent() {  
  if (net != null) {  
    if (net.indexOf("water")!=-1) foundWater(net);
  }
}
 

http://toxi.co.uk/
ian

WWW
Re: carnivore packet searching
« Reply #2 on: Oct 10th, 2003, 5:43pm »

thanks - i'll give that a shot.  
 
ian
 
fry


WWW
Re: carnivore packet searching
« Reply #3 on: Oct 14th, 2003, 10:26pm »

it's also possible to do the threading the same way you would with java (see the java tutorial for how to use threads).  
 
using indexOf will be faster than splitStrings.. also, the net code is a bit slower than we'd like, but that'll be fixed shortly.
 
Pages: 1 

« Previous topic | Next topic »