| |

VerySource

 Forgot password?
 Register
Search
View: 935|Reply: 3

Problems displaying jpcap.loopPacket () results using JList

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-3 16:50:01
| Show all posts |Read mode
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!
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-8-9 21:30:01
| Show all posts
Look at the API documentation of JPcap, it is written like this in the API documentation
public int loopPacket(int count,PacketReceiver handler)

Captures the specified number of packets consecutively.

Consecutively means continuous. I guess it’s grabbing count packets at once, so you add directly in Frame.listMode1.addElement(packet);. I think so, I don’t know if it’s right.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-2 20:45:01
| Show all posts
Don't use jpacp.loopPacket(), use JpcapCaptor.getPacket().This method is to capture a packet every time, and process it after it is captured, and use a loop to process it, which can achieve your purpose.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-3 23:30:01
| Show all posts
The capture thread blocked your swing event dispatch thread.
Plus multi-threading
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list