예제 #1
0
        public void ListenMessage(object o, ReceivedEventArgs e)
        {
            if (PacketView.InvokeRequired)
            {
                
                    ReceivedHandler d = new ReceivedHandler(ListenMessage);
                    this.Invoke(d, new object[] { o, e});
            }
            else
            {
                byte[] data = e.Data;
                int length = data.Length;
                Boolean isEcho = this.cbAutoSend.Checked;
                string connId = "" + o;
                if (isEcho)
                {
                    commServer.Send(connId, data, data.Length);
                }

                
                if (PacketView.Items.Count > 200)
                    PacketView.Items.Clear();

                ListViewItem item = PacketView.Items.Insert(0, "" + PacketView.Items.Count);
                item.SubItems.Add("" + connId);
                item.SubItems.Add("" + e.RemoteHost.ToString());

                string msg = ParseUtil.ParseString(data, length);
                if (rbHex.Checked)
                {
                    msg = ParseUtil.ToHexString(data, length);
                }

                string strDate = DateTime.Now.ToString("HH:mm:ss");
                item.SubItems.Add(strDate);

                item.SubItems.Add(msg);
                item.SubItems.Add("" + length);
                if (cbLog.Checked)
                {
                    logger.Info(e.RemoteHost.ToString() + " " + msg);
                }
                //item.SubItems.Add("" + msg.MsgContentDesc);
            }
        }
예제 #2
0
        public void ListenMessage(object o, ReceivedEventArgs e)
        {
            if (PacketView.InvokeRequired)
            {
                try
                {
                    ReceivedHandler d = new ReceivedHandler(ListenMessage);
                    this.Invoke(d, new object[] {o, e });
                }
                catch (System.Exception ex)
                {
                    logger.Error(ex.Message);
                    logger.Error(ex.StackTrace);
                }
            }
            else
            {
                if (PacketView.Items.Count > 200)
                    PacketView.Items.Clear();

                ListViewItem item = PacketView.Items.Insert(0, "" + PacketView.Items.Count);

                int length = e.Data.Length;
                string strDate = DateTime.Now.ToString("HH:mm:ss");
                item.SubItems.Add(strDate);
                string msg = ParseUtil.ParseString(e.Data, length);
                if (rbHex.Checked)
                    msg = ParseUtil.ToHexString(e.Data, length);
                item.SubItems.Add(msg);
                item.SubItems.Add("" + length);

                if (cbLog.Checked)
                {
                    logger.Info(e.RemoteHost.ToString() + " " + msg);
                }
                //item.SubItems.Add("" + msg.MsgContentDesc);
            }
        }