Exemplo n.º 1
0
        ////粘包拆包问题 : 解决决策 :消息头和消息尾。
        //// 比如 发送的数据:  12345
        //void test()
        //{
        //    byte[] bt = Encoding.Default.GetBytes("12345");

        //    //怎么构造
        //    //头:消息的长度 bt.Length
        //    //尾:具体的消息 bt
        //    int length = bt.Length;
        //    byte[] bt1 = BitConverter.GetBytes(length);
        //    //得到消息就是:bt1 + bt

        //    ///怎么读取
        //    //int length = 前四个字节转成int类型
        //    //然后读取 这个长度的数据
        //}

        #endregion

        #region 断开连接

        /// <summary>
        /// 断开连接
        /// </summary>
        public void Disconnect()
        {
            //清空数据
            dataCache.Clear();
            isReceiveProcess = false;
            sendQueue.Clear();
            isSendProcess = false;

            ClientSocket.Shutdown(SocketShutdown.Both);
            ClientSocket.Close();
            ClientSocket = null;

            ConnHelper.CLose(mySqlConn);
        }