|
I used JBuilder2006 to make a small program that captures packets and then echoes.
Event trigger:
public void jButton1_mouseClicked (MouseEvent e) {
try {
jpcap = Jpcap.openDevice (Jpcap.getDeviceList () [1], 1024, false, 10000);
jpcap.loopPacket (10, new GetPacket ());
----------
}
catch (java.io.IOException f) {
System.out.println ("We can't open device");
}
}
The GetPacket () class is
import jpcap. *;
import java.util.Vector;
import javax.swing.JList;
/ **
* <p> Title: </ p>
*
* <p> Description: </ p>
*
* <p> Copyright: Copyright (c) 2006 </ p>
*
* <p> Company: </ p>
*
* @author not attributable
* @version 1.0
* /
class GetPacket implements JpcapHandler {
public void handlePacket (Packet packet) {
Frame.listMode1.addElement (packet);
}
}
/ * listMode1 is a static object for display.It is used to add the display line of a package to a JList. It is defined as public static DefaultListModel listMode1 = new DefaultListModel ();
JList jList1 = new JList (listMode1); * /
Using jpcap.loopPacket (10, new GetPacket ()), what I want is to grab a total of ten packets and grab one packet to display one, but the situation I have here is that after all the packets are captured, they are displayed together. This is inconsistent with the method definition of Jpcap.loopPacket (). What caused it? Please enlighten me, 3Q! |
|