示例#1
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="msgBody"></param>
        private void sendMsg(byte[] msgBody, bool isResent = false)
        {
            byte[] msg = null;
            if (isResent)
            {
                msg = msgBody;
                resendCount++;
            }
            else
            {
                resendCount = 0;
                msg         = AGVMessageHelper.GenMsg(msgBody);
            }
            if (resendCount > 2)
            {
                LogUtil.Logger.Error("【发送超时且超出最大发送次数】");
            }
            else
            {
                currentCmd = msg;
                if (ConnectServer())
                {
                    tcpClient.Send(msg, msg.Length, SocketFlags.None);
                    // tcpClient.ReceiveTimeout = 5000;

                    SendMessageText.AppendText(ReadMessage.Parser.readMessage(msg) + "\n");
                }
            }
        }
示例#2
0
        /// <summary>
        /// 向客户端发送消息
        /// </summary>
        /// <param name="clientIP"></param>
        /// <param name="msgBody"></param>
        private void sendMsgToClient(string clientIP, byte[] msgBody)
        {
            byte[] msg = AGVMessageHelper.GenMsg(msgBody);
            clients[clientIP].Send(msg, msg.Length, SocketFlags.None);
            string SendMeans = ReadMessage.Parser.readMessage(msg);

            this.Dispatcher.Invoke(new Action(() => { SendText.AppendText(SendMeans + "\n"); }));
        }