I'm using the lib SharpPCap to capture packets, then analyse them to find the flv video address in PacketArrivalEventHandler function. The main part of class is like this:
class addrdetector
{
private LivePCapDevice device;
private device_OnPacketArrival(object sender, CaptureEventArgs e)
{
/* some analysis and some output */
if (match)
{
device.StopCapture();
device.Close();
}
}
public Analyse()
{
var devices = LivePcapDeviceList.Instance;
device = devices[2];
device.OnPacketArrival +=
new PacketArrivalEventHandler(device_OnPacketArrival);
device.Open();
device.StartCapture();
}
}
if I have 2 instances of addrdector in a program, the first instance has the correct output, but the second hasn't any output. It seems like the second can't capture any packet.
I've tested 2 i开发者_高级运维nstances of LivePCapDevice in a same main funcion, and they work correctly. They can also work in 2 EXE.s. But I can't find out why they conflict in a program... Thanks~Clone the SharpPcap source and look at the examples
I can't reference the exact example at the moment because I'm away from my development computer but I'm absolutely positive that there's an example of how to add additional LivePcapDevice instances.
It's not impossible but the solution isn't intuitive. I think the example that uses is is called something along the lines of "CaptureMultipleFilters".
Good luck and I'll update this answer with better data as soon as I can.
Nameproject : MultipleFiltersOnDevice.
And the code is the following :
var device1 = CaptureDeviceList.Instance[i];
var device2 = CaptureDeviceList.New()[i]; // NOTE: the call to New()
It works for me.
精彩评论