It's not a secret anymore!*
The moose likes Swing / AWT / SWT and the fly likes Not able to see network activity in JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Not able to see network activity in JFrame" Watch "Not able to see network activity in JFrame" New topic
Author

Not able to see network activity in JFrame

Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 198
Hi,

I am trying to develop an application which will be showing a TimeSeries graph(related library JFreeChart) displaying network activity related to a particular network interface embedded in a JFrame.I have created a JPopUpMenu which is having containing a list of JMenuItems showing network interfaces as their String values.Menu is popping up correctly

Further I am selecting a JMenuItem related to a particular network interface to show network activity in TimeSeries graph.On selecting a JMenuItem I can see that graph is moving on constantly but not able to see any network activity.

Pasted the code below :



Futher I can see that packetArrived method of PacketListener is not being overridden by class PacketHandler as I am not able to see data packets on console and static list in main class is also empty.

Please help me out regarding same.

Thanks!

>
Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 430
    
    1

First, I would try to understand if PacketCapture is doing is work or not, and if it's working, if there are problems instead with updating your JFreeChart.
What happen if you try and collect data about network traffic in a simple, textual tool without dealing with Swing ?
Does it work ?

Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 198
Hi Claude,
Thanks for your reply.
I tried to print packet data over console as in packetArrived() method.Its not working as well.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41089
    
  44
So... the question is not really about Swing, it is about how to make that networking library work in general?


Ping & DNS - my free Android networking tools app
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 198
I was able to open the network device and was able to print raw network data over the console before adding the chart to application but its more looking like a problem related to networking.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41089
    
  44
I would advise to start with an app that has no GUI at all, and just interacts with the networking/library code. Once you have that working, adding the GUI should be easier.
Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 430
    
    1

Ulf Dittmer wrote:I would advise to start with an app that has no GUI at all, and just interacts with the networking/library code. Once you have that working, adding the GUI should be easier.

I agree... from your post it's not clear if the whole thing stopped working after you added GUI parts.
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 198
Hi People,

Thanks for your responses so far!
I have tried to print network packet over console using below code :



This code is either printing all the network interfaces in your system or printing network packet across console if you are providing name of any of interfaces available explicitly.Outputs in both the conditions are given below :


Available network devices on your machine:
PacketCapture: loading native library jpcap.. ok
\Device\NPF_{FDEDD322-89A9-46CD-BD38-18E5B2A98AB0}
Microsoft
\Device\NPF_{E7FC683A-97FA-48C5-863B-F9E4945E94DB}
Realtek PCIe GBE Family Controller
\Device\NPF_{BBA1CB68-B3FA-4CE9-8610-F402EEA70DEE}
Bluetooth PAN Driver
\Device\NPF_{2D88147C-3A7D-44B9-9770-7B636AFB33AC}
Microsoft




PacketCapture: loading native library jpcap.. ok
Using device '\Device\NPF_{BBA1CB68-B3FA-4CE9-8610-F402EEA70DEE}'
In PacketHandler class
Capturing packets...


In second output I am not able to see network packets at all no matter how much time I am going to wait.(You can increase and decrease value of waiting time by altering the value of variable INFINITE.INFINITE=-1 means program will never terminate)


So from message I can see that native library(jpcap.dll) is loading perfectly which has been kept in C:\Windows\System32.But it's also clear that packetArrived() method declared in PacketListener(Provided by jpcap.jar file) interface is not being defind by my class PacketHandlerC.

Not sure why this is not working!
Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 430
    
    1

Are you using any open source library to monitor network activity ?
If it's so, I'd like to have a try with it... and maybe I'll able to help you (I'm quite interested in such things like network monitoring).

Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 198
Yes,Jpcap is an opensource networking library.Thanks for your response...
Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 430
    
    1

Ok, it seems that JPCAP does support only Windows 32, so I searched for another open source library.

I found jnetpcap, it seems very good, at least because website offers a tutorial and some examples.

You may download both 32 and 64 version of this library.. and you need an implementation of libpcap for windows (i used WinPCap which
is opensource too) for make the whole thing work.

I followed the classical example published on website of JNetPCap and I get it running in no time...

Hope this helps !


Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 198
But still not able to understand because from console I can see that required dll and jars are loading correctly.It should give linkage error if any problem is there as I have got during initial set-ups
Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 430
    
    1

Most of time, when output to console works and gui stuff doesn't, there's something wrong with gui updates. Did you try to update gui in a separate thread?
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 198
Hi Claude,

I tried to update GUI in separate thread as suggested by you and it seems that finally I got things working.Thanks for same.Below is the modified code :



attached herein are the screen-shot of GUI for one of the interfaces

and below is the output for packet data from console for same interface



PacketCapture: loading native library jpcap.. ok
\Device\NPF_{2D88147C-3A7D-44B9-9770-7B636AFB33AC}
packetList []
1
Received packet ([UDPPacket: 95.181.56.250.25253 -> 192.168.1.2.44363 l=8,101])
2
Received packet ([UDPPacket: 192.168.1.2.44363 -> 95.181.56.250.25253 l=8,287])
3
Received packet ([TCPPacket: 74.125.236.85.https -> 192.168.1.2.50903 ack[0x33454c6d] psh l=20,58])
4
Received packet ([EthernetPacket: c0:18:85:7b:41:b2 -> 33:33:00:01:00:02 proto=0x86dd l=14])
5
Received packet ([TCPPacket: 192.168.1.2.50903 -> 74.125.236.85.https ack[0x73c7a825] l=20,0])
6
Received packet ([EthernetPacket: c0:18:85:7b:41:b2 -> 33:33:00:01:00:02 proto=0x86dd l=14])
7
Received packet ([UDPPacket: 91.147.203.111.60909 -> 192.168.1.2.44363 l=8,103])
8
Received packet ([UDPPacket: 192.168.1.2.44363 -> 91.147.203.111.60909 l=8,289])
9
Received packet ([UDPPacket: 111.232.5.8.11819 -> 192.168.1.2.44363 l=8,49])
10
Received packet ([UDPPacket: 192.168.1.2.44363 -> 109.248.119.97.43775 l=8,67])
tlen 525
tlen 525
tlen 525
tlen 525


But still I can see three problems/questions here :

1. Why there is no data in ArrayList packetList still

2. Why I am not seeing any ups and downs and spikes in graph as its moving.Value of packet length(tlen) is also indicating the same.

3. I think I am not able to see my wifi interface in interface selection drop-down menu which is Broadcom 4313GN 802.1 b/g/n 1x1 Wi-Fi Adapter{4d36e972-e325-11ce-bfc1-08002be10318} so unable to capture traffic from same

Please refer screen-shots at end of page. Thin straight red line in first screen-shot is showing network traffic after selection of interface in second screen-shot.


[Thumbnail for GUI_screen-shot_1.png]

[Thumbnail for GUI_screen-shot_2.png]

Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 430
    
    1

Hi Ankit,

of course I cannot do a full debug of your code. My advice is pretty the same: before going with GUI, test all functionalities with simple console program.
Moreover, I would instantiate a specific class CustomPacketListener (which extends Thread) directly in main program, and expose some methods to add
NICs to listen to from a caller.

Pseudo code:



and so on....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to see network activity in JFrame
 
Similar Threads
Displaying scalable vector graphics on ibm aix
java JFreechart compress the line over the time period
calling an application frame with another application frame using mouse actions
Problem in displaying waterfall chart with -ve values
Dynamic chart in swing