void asyClient_OnExceptionHandler(IOCPSocket socket, AppExceptionEnum id, string msg)
 {
     if ((id == AppExceptionEnum.Error) || (id == AppExceptionEnum.SocketDisponsed))
     {
         socketClosed = true;
         SOCKET_STATE = TCP_SocketState.SOCKET_CLOSED;
     }
 }
 void asyClient_OnAppExceptionHandler(IOCPSocket socket, AppExceptionEnum id, string msg)
 {
     if (id == AppExceptionEnum.StopOK)
     {
         socketClosed = true;
         SOCKET_STATE = TCP_SocketState.SOCKET_CLOSED;
     }
     if (id == AppExceptionEnum.StartOK)
     {
         socketReady  = true;
         SOCKET_STATE = TCP_SocketState.SOCKET_CONNECTED;
     }
 }
        private void asyClient_OnDataHandler(IOCPSocket socket)
        {
            SOCKET_STATE = TCP_SocketState.SOCKET_CONNECTED;

            try
            {
                Array.Copy(socket.SocketObject.Buffer, 0, socketData.Buffer.Buffer, socketData.Buffer.Length, socket.SocketObject.DataLength);
                socketData.Buffer.Length = socketData.Buffer.Length + socket.SocketObject.DataLength;
            }
            catch
            {
                return;
            }
        }
        public TcpCommunication()
        {
            socketData = new SocketCommandTag();

            isLogined = false;

            //等待时长
            TcpWait = int.Parse(CommonUtil.ReadAppSetting("GetwayWait"));

            //正在连接
            SOCKET_STATE = TCP_SocketState.SOCKET_CONNECTION;

            asyClient = new AsyClient(IPAddress.Parse(CommonUtil.ReadAppSetting("GetwayIP")), int.Parse(CommonUtil.ReadAppSetting("GetwayPort")));

            asyClient.OnDataHandler         += asyClient_OnDataHandler;
            asyClient.OnCloseHandler        += asyClient_OnCloseHandler;
            asyClient.OnAppExceptionHandler += asyClient_OnAppExceptionHandler;
            asyClient.OnExceptionHandler    += asyClient_OnExceptionHandler;

            asyClient.StartClient();
        }
 void asyClient_OnCloseHandler(IOCPSocket socket, string msg)
 {
     socketClosed = true;
     socketReady  = false;
     SOCKET_STATE = TCP_SocketState.SOCKET_CLOSED;
 }