Exemplo n.º 1
0
        /// <summary>
        /// Validates the parameters and starts the monitor.
        /// </summary>
        public void Start()
        {
            if (_monitor != null)
            {
                _monitor.Stop();
                _monitor = null;
            }

            if (MessageReceivedEventHandler == null)
            {
                throw new ArgumentException("MessageReceived delegate must be specified.");
            }

            _monitor = new TCPNetworkMonitor();
            _monitor.Config.ProcessID     = ProcessID;
            _monitor.Config.ProcessIDList = ProcessIDList;
            if (_monitor.Config.ProcessID == 0)
            {
                _monitor.Config.WindowName = Region == Region.China ? "最终幻想XIV" : "FINAL FANTASY XIV";
            }
            _monitor.Config.MonitorType       = MonitorType;
            _monitor.Config.LocalIP           = LocalIP;
            _monitor.Config.UseRemoteIpFilter = UseRemoteIpFilter;

            _monitor.DataSentEventHandler     = (TCPConnection connection, byte[] data) => ProcessSentMessage(connection, data);
            _monitor.DataReceivedEventHandler = (TCPConnection connection, byte[] data) => ProcessReceivedMessage(connection, data);

            _monitor.Start();
        }
        /// <summary>
        /// Validates the parameters and starts the monitor.
        /// </summary>
        public void Start()
        {
            if (_monitor != null)
            {
                _monitor.Stop();
                _monitor = null;
            }

            if (MessageReceived == null)
            {
                throw new ArgumentException("MessageReceived delegate must be specified.");
            }

            _monitor           = new TCPNetworkMonitor();
            _monitor.ProcessID = ProcessID;
            if (_monitor.ProcessID == 0)
            {
                _monitor.WindowName = Region == Common.Region.CN ? "最终幻想XIV" : "FINAL FANTASY XIV";
            }
            _monitor.MonitorType     = MonitorType;
            _monitor.LocalIP         = LocalIP;
            _monitor.UseSocketFilter = UseSocketFilter;

            _monitor.DataSent     = (string connection, byte[] data) => ProcessSentMessage(connection, data);
            _monitor.DataReceived = (string connection, byte[] data) => ProcessReceivedMessage(connection, data);

            _monitor.Start();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Validates the parameters and starts the monitor.
        /// </summary>
        public void Start()
        {
            if (_monitor != null)
            {
                _monitor.Stop();
                _monitor = null;
            }

            if (MessageReceived == null)
            {
                throw new ArgumentException("MessageReceived delegate must be specified.");
            }

            _monitor           = new TCPNetworkMonitor();
            _monitor.ProcessID = ProcessID;
            if (_monitor.ProcessID == 0)
            {
                _monitor.WindowName = "FINAL FANTASY XIV";
            }
            _monitor.MonitorType = MonitorType;
            _monitor.LocalIP     = LocalIP;

            _monitor.DataSent     = ProcessSentMessage;
            _monitor.DataReceived = ProcessReceivedMessage;

            _monitor.Start();
        }
Exemplo n.º 4
0
        public void TCPNetworkMonitor_RawSocket_SendAndReceiveData()
        {
            TCPNetworkMonitor monitor = new TCPNetworkMonitor();

            monitor.ProcessID       = (uint)Process.GetCurrentProcess().Id;
            monitor.MonitorType     = TCPNetworkMonitor.NetworkMonitorType.RawSocket;
            monitor.DataReceived   += (string connection, byte[] data) => DataReceived(connection, data);
            monitor.DataSent       += (string connection, byte[] data) => DataSent(connection, data);
            monitor.UseSocketFilter = false;

            monitor.Start();
            // start a dummy async download
            System.Net.WebClient client = new System.Net.WebClient();
            Task t = client.DownloadStringTaskAsync("http://www.google.com");

            t.Wait();

            t = client.DownloadStringTaskAsync("http://www.google.com");
            t.Wait();

            for (int i = 0; i < 100; i++)
            {
                if (dataSentCount > 1 && dataReceivedCount > 1)
                {
                    break;
                }

                System.Threading.Thread.Sleep(10);
            }

            monitor.Stop();

            Assert.IsTrue(dataReceivedCount >= 1);
            Assert.IsTrue(dataSentCount >= 1);
        }
        /// <summary>
        /// Validates the parameters and starts the monitor.
        /// </summary>
        public void Start()
        {
            if (_monitor != null)
            {
                _monitor.Stop();
                _monitor = null;
            }

            if (MessageReceived == null)
            {
                throw new ArgumentException("MessageReceived delegate must be specified.");
            }

            _monitor = new TCPNetworkMonitor
            {
                MonitorType     = MonitorType,
                LocalIP         = LocalIP,
                UseSocketFilter = UseSocketFilter,
                DataSent        = ProcessSentMessage,
                DataReceived    = ProcessReceivedMessage,
                ProcessID       = ProcessID,
            };

            if (_monitor.ProcessID == 0)
            {
                _monitor.WindowName = Region == Region.China ? "最终幻想XIV" : "FINAL FANTASY XIV";
            }

            _monitor.Start();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Stops the monitor if it is active.
        /// </summary>
        public void Stop()
        {
            _monitor?.Stop();
            _monitor = null;

            _sentDecoders.Clear();
            _receivedDecoders.Clear();
        }