wxr
2021-07-01 43b0d5870d528f23ecd6aeceb6cfd4325188b46f
HDL_ON/DAL/DriverLayer/Control_TcpClient.cs
@@ -7,10 +7,6 @@
{
    public class Control_TcpClient
    {
        /// <summary>
        /// 通讯ID
        /// </summary>
        public const int msg_id = 1;
        //声明IP,端口,和一个用来连接的Socket
        public string _ip;
@@ -41,10 +37,11 @@
            {
                _tcpClient.Connect(IPAddress.Parse(_ip), _port);
                Task.Run(new Action(ReceiveMessage));//开启线程,不停接收消息
                MainPage.Log($"打开tcp client{_ip}:{_port}");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                MainPage.Log(e.Message);
                throw;
            }
            return true;//返回连接状态
@@ -69,7 +66,11 @@
        public void SendMessage(byte[] bytes)
        {
            NetworkStream networkStream = _tcpClient.GetStream();
            networkStream.Write(bytes, 0, bytes.Length);
            if (networkStream.CanWrite)
            {
                networkStream.Write(bytes, 0, bytes.Length);
            }
            //networkStream.Close();
        }
        /// <summary>
@@ -127,18 +128,7 @@
            }
        }
        #region A协议
        /// <summary>
        /// 发送A协议数据
        /// </summary>
        /// <param name="topic"></param>
        public void SendData(string topic)
        {
            string topicString = "Topic:" + topic + "/r/n";
            string lenghtString = "Length:" + "/r/n" + "/r/n";
        }
        #endregion
    }
}