public bool Start(int interval = 1000) { #region 启动系统性能计数器统计 bool isSucceed; try { isSucceed = NetFlow.Start(interval); NetFlow.DataMonitorEvent += DataMonitorEvent; IsNetFlowRun = true; } catch { return(false); } if (!isSucceed) { return(false); } #endregion #region 启动Socket包统计 if (CheckPermission.IsAdmin()) { var hosts = NetCardInfoTool.GetIPv4Address(); AllIPv4Address = NetCardInfoTool.GetAllIPv4Address(); foreach (var host in hosts) { try { var p = new NetPacketTool(host); p.NewPacket += NewPacketEvent; p.Start(); NetPacketList.Add(p); } catch { // ignored } } if (ListTool.HasElements(NetPacketList)) { IsNetPacketRun = true; } } #endregion return(true); }
public void Stop() { if (IsNetFlowRun) { NetFlow.Stop(); IsNetFlowRun = false; } if (IsNetPacketRun) { NetPacketList.ForEach(x => { x.Stop(); }); IsNetPacketRun = false; } }
private void CheckRestart() { var rest = false; var instance = NetCardInfoTool.GetInstanceNames(); if (ListTool.IsNullOrEmpty(NetFlow.Instances) && ListTool.HasElements(instance)) { rest = true; } if (ListTool.HasElements(NetFlow.Instances) && ListTool.HasElements(instance) && string.Join(@"-", NetFlow.Instances) != string.Join(@"-", instance)) { rest = true; } if (rest) { //重启 系统性能计数器 NetFlow.Restart(); //重启 抓包监听 var hosts = NetCardInfoTool.GetIPv4Address(); AllIPv4Address = NetCardInfoTool.GetAllIPv4Address(); foreach (var host in hosts) { try { if (NetPacketList.All(x => x.IP.ToString() != host.ToString())) { var p = new NetPacketTool(host); p.NewPacket += NewPacketEvent; p.Start(); NetPacketList.Add(p); } } catch { // ignored } } } }
/** * Returns the client's average packet frequency in packets/sec. * * @param client Player's index. * @param flow Traffic flowing direction. * @return Packet frequency. * @error Invalid client index, client not connected, or fake client. */ public static float GetClientAvgPackets(int client, NetFlow flow) { throw new NotImplementedException(); }
/** * Returns the client's current latency (RTT), more accurate than GetAvgLatency but jittering. * * @param client Player's index. * @param flow Traffic flowing direction. * @return Latency, or -1 if network info is not available. * @error Invalid client index, client not connected, or fake client. */ public static float GetClientLatency(int client, NetFlow flow) { throw new NotImplementedException(); }