Beispiel #1
0
        private void m_SndMessageAsQueue()
        {
            isSndComplete = false;
            int bodyLength = m_taskList[0].Count();

            byte[] headBytes = m_GetHeadBytes(bodyLength);
            if (headBytes != null)
            {
                DebugQy.LogTag("Jisight_Tcp_Send Head:", headBytes.Length.ToString());
                DebugQy.LogTag("Jisight_Tcp_Send Body:", bodyLength.ToString());
                byte[] intactBytes = new byte[headBytes.Length + bodyLength];
                headBytes.CopyTo(intactBytes, 0);
                m_taskList[0].CopyTo(intactBytes, headBytes.Length);
                m_tgWorkSocket.TryAnsyncSendMessage(intactBytes);
            }
            else
            {
                DebugQy.LogWarning("SendMessageHandle() : Send data size is out of rang. So cansole send.");
            }
            m_taskList.RemoveAt(0);
            if (m_taskList.Count > 0)
            {
                m_SndMessageAsQueue();
            }
            else
            {
                isSndComplete = true;
            }
        }
Beispiel #2
0
        /// <summary>
        /// 协议发送事件失败回调
        /// </summary>
        /// <param name="sender">触发该事件的SocketQY</param>
        /// <param name="eventArgs">参数</param>
        private void m_ProtocolRecvCompleteCallback(ISocketQy sender, ISocketRecEventArgs eventArgs)
        {
            string recStr = Encoding.ASCII.GetString(eventArgs.ReceiveBuffer);

            DebugQy.LogTag("ClientController", "Recv Complete CallBack:" + recStr);
            m_FirSomeEvent(EVENT_TYPE.RECEIVE, COMPLETE_OR_FAILED.COMPLETE, recStr);
        }
Beispiel #3
0
        private void m_ReceiveBodyDataCallBack(ISocketQy sender, ISocketRecEventArgs args)
        {
            int currentBufferSize = args.NeedRecvBufferSize;

            if (currentBufferSize != m_nextPackageSize)
            {
                DebugQy.LogWarning("m_ReceiveBodyDataCallBack(): rec buffer size != 'BODY_BUFFER_SIZE' . Please check your operate in receive.");
                DebugQy.LogWarning("'I Has stop your receive function !' ------- from writer. ");
                if (RecMsgFailedEvent != null)
                {
                    RecMsgFailedEvent(sender, args);
                }
                StopReceiveMessage();
                return;
            }
            DebugQy.Log("'BODY_PACKAGE' has received.");
            m_nextHeadOrBody  = HEAD_BODY_PACKET.HEAD;
            m_nextPackageSize = HEAD_BUFFER_SIZE;
            DebugQy.Log("start receive [BODY] :-------- thread.set      ↑↑↑↑↑\n ");
            m_recEventWaitHandle.Set();
            if (RecMsgCompleteEvent != null)
            {
                RecMsgCompleteEvent(sender, args);
            }
        }
Beispiel #4
0
        private void m_ReceiveMessageEventFiring(FIRING_D_C_F firType, ISocketRecEventArgs recArgs, string funcionTag)
        {
            switch (firType)
            {
            case FIRING_D_C_F.DEFAULT:
                DebugQy.LogTag(funcionTag, "begin receive . please wait callback.", "#3C9553FF");
                break;

            case FIRING_D_C_F.FIR_COMPLETE:
                DebugQy.LogTag(funcionTag, firType.ToString(), "#3C9553FF");
                if (AnsyncRecMsg_Complete_Event != null)
                {
                    ISocketRecEventArgs _args = recArgs;
                    AnsyncRecMsg_Complete_Event(this, _args);
                }
                break;

            case FIRING_D_C_F.FIR_FAILED:
                DebugQy.LogTag(funcionTag, firType.ToString() + recArgs.ErrMessage, "#BB7979FF");
                if (AnsyncRecMsg_Failed_Event != null)
                {
                    ISocketRecEventArgs _args = recArgs;
                    AnsyncRecMsg_Failed_Event(this, _args);
                }
                break;

            default:

                break;
            }
        }
Beispiel #5
0
        private byte[] m_tempRecvBuffer       = new byte[RECEIVE_BUFFER_SIZE]; //每次 receive 回来的数据

        public bool SetEndPoint(string ip, int port)
        {
            bool paramIsRight;

            if (Regex.IsMatch(ip, @"[0-255]?.[0-255]?.[0-255]?"))
            {
                m_ipAddress = IPAddress.Parse(ip);
                if (port >= IPEndPoint.MinPort && port <= IPEndPoint.MaxPort)
                {
                    m_ipEndPoint = new IPEndPoint(m_ipAddress, port);
                    paramIsRight = true;
                }
                else
                {
                    //端口输入有误
                    paramIsRight = false;
                    DebugQy.LogWarning("--> TryConnectTo() function. 'Port' value is out of range. \n" +
                                       "Please check 'out bool : paramIsRight' to handle your 'port'.");
                }
            }
            else
            {
                //Ip输入有误
                paramIsRight = false;
                DebugQy.LogWarning(" --> TryConnectTo() function. 'Ip' format is wrong ." +
                                   "Please check 'out bool : paramIsRight' to handle your 'Ip'");
            }
            return(paramIsRight);
        }
Beispiel #6
0
        private void m_SendMessageEventFiring(FIRING_D_C_F firType, ISocketSndEventArgs sendArgs, string funcionTag)
        {
            switch (firType)
            {
            case FIRING_D_C_F.DEFAULT:
                DebugQy.LogTag(funcionTag, "buffer has send . please wait callback.", "#3487E8FF");
                break;

            case FIRING_D_C_F.FIR_COMPLETE:
                DebugQy.LogTag(funcionTag, firType.ToString(), "#3487E8FF");
                if (AnsyncSendMsg_Complete_Event != null)
                {
                    ISocketSndEventArgs _args = sendArgs;
                    AnsyncSendMsg_Complete_Event(this, _args);
                }

                break;

            case FIRING_D_C_F.FIR_FAILED:
                DebugQy.LogTag(funcionTag, firType.ToString() + sendArgs.ErrMessage, "#BB7979FF");
                if (AnsyncSendMsg_Failed_Event != null)
                {
                    ISocketSndEventArgs _args = sendArgs;
                    AnsyncSendMsg_Failed_Event(this, _args);
                }
                break;

            default:

                break;
            }
        }
Beispiel #7
0
        private void m_ConnectEventFiring(FIRING_D_C_F firType, ISocketConEventArgs conArgs, string funcionTag)
        {
            switch (firType)
            {
            case FIRING_D_C_F.DEFAULT:

                break;

            case FIRING_D_C_F.FIR_COMPLETE:
                DebugQy.LogTag(funcionTag, firType.ToString(), "#59A7CEFF");
                if (AnsyncConnectTo_Complete_Event != null)
                {
                    ISocketConEventArgs _args = conArgs;
                    AnsyncConnectTo_Complete_Event(this, _args);
                }
                break;

            case FIRING_D_C_F.FIR_FAILED:
                DebugQy.LogTag(funcionTag, firType.ToString() + conArgs.ErrMessage, "#BB7979FF");
                if (AnsyncConnectTo_Failed_Event != null)
                {
                    ISocketConEventArgs _args = conArgs;
                    AnsyncConnectTo_Failed_Event(this, conArgs);
                }
                break;

            default:

                break;
            }
        }
Beispiel #8
0
        private void m_DeleteEventFiring(FIRING_D_C_F firType, IDeleteEventArgs stateArgs, string funcionTag)
        {
            switch (firType)
            {
            case FIRING_D_C_F.DEFAULT:

                break;

            case FIRING_D_C_F.FIR_COMPLETE:
                DebugQy.LogTag(funcionTag, firType.ToString(), "#59A7CEFF");
                if (DeleteCompleteEvent != null)
                {
                    IDeleteEventArgs _args = stateArgs as IDeleteEventArgs;
                    DeleteCompleteEvent(this, _args);
                }
                break;

            case FIRING_D_C_F.FIR_FAILED:
                DebugQy.LogTag(funcionTag, firType.ToString() + stateArgs.ErrMessage, "#BB7979FF");
                if (DeleteFailedEvent != null)
                {
                    IDeleteEventArgs _args = stateArgs as IDeleteEventArgs;
                    DeleteFailedEvent(this, _args);
                }
                break;

            default:

                break;
            }
        }
Beispiel #9
0
        private void m_ConnectCallBack(IAsyncResult asyncResult)
        {
            FIRING_D_C_F        _firEventType = FIRING_D_C_F.DEFAULT;
            string              errorMessage  = string.Empty;
            SocketAnsynParam    _ansynParam   = asyncResult.AsyncState as SocketAnsynParam;
            ISocketConEventArgs _conEventArgs = _ansynParam.transEventArgs as ISocketConEventArgs;

            try
            {
                _ansynParam.workSocket.EndConnect(asyncResult);
                errorMessage  = "√√√ no mistake √√√";
                _firEventType = FIRING_D_C_F.FIR_COMPLETE;
            }
            catch (ArgumentNullException ee)
            {
                errorMessage = "×××  ArgumentNullException  ×××:"
                               + " asyncResult 为 null。"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (ArgumentException ee)
            {
                errorMessage = "×××  ArgumentException  ×××:"
                               + " BeginConnect 方法调用未返回 asyncResult。"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (SocketException ee)
            {
                errorMessage = "×××  SocketException  ×××:"
                               + " 试图访问套接字时发生错误。"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (ObjectDisposedException ee)
            {
                errorMessage = "×××  ObjectDisposedException  ×××:"
                               + "Socket 已关闭。"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (InvalidOperationException ee)
            {
                errorMessage = "×××  InvalidOperationException  ×××:"
                               + "先前曾为异步连接调用过 EndConnect。"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (Exception ee)
            {
                errorMessage = "×××  Unknown exception  ××× :"
                               + "Firing other unknown exception !!!!!!"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            DebugQy.LogTag("<<<<<<< CON ENP IN CLIENT >>>>>>>", "*-*-*-*-*[ out ]*-*-*-*-*");
            _conEventArgs.SetErrMessage(errorMessage);
            m_ConnectEventFiring(_firEventType, _conEventArgs, "m_ConnectCallBack");
        }
Beispiel #10
0
 private void m_SendMessageFaliedCallBack(ISocketQy sender, ISocketSndEventArgs evetArgs)
 {
     DebugQy.LogTag("HeadBodyTcpProtocol", "Failed Call Back in 'Protocol'.");
     if (SendMsgFailedEvent != null)
     {
         SendMsgFailedEvent(sender, evetArgs);
     }
 }
Beispiel #11
0
 public void StopReceiveMessage()
 {
     if (m_recMsgThread != null && m_recMsgThread.IsAlive)
     {
         m_recMsgThread.Abort();
         DebugQy.Log("end receive in protocol.");
     }
 }
Beispiel #12
0
 public void Dispose()
 {
     DebugQy.LogTag("ClientSocket", "Disposed !!!!!!!!", "#BB7979FF");
     if (m_clientSocket.Connected)
     {
         m_clientSocket.Shutdown(SocketShutdown.Both);
         m_clientSocket.Close();
     }
 }
Beispiel #13
0
 public void SetTargetSocket(ISocketQy workSocket)
 {
     if (workSocket == null)
     {
         DebugQy.LogException(new NullReferenceException("workSocket is null.Check your SetTargetSocket()."));
         return;
     }
     m_tgWorkSocket = workSocket;
     m_tgWorkSocket.AnsyncSendMsg_Complete_Event += m_SendMessageCompleteCallBack;
     m_tgWorkSocket.AnsyncSendMsg_Failed_Event   += m_SendMessageFaliedCallBack;
     m_tgWorkSocket.AnsyncRecMsg_Complete_Event  += m_ReceiveMsgCompleteCallBack;
     m_tgWorkSocket.AnsyncRecMsg_Failed_Event    += m_ReceiveMsgFailedCallBack;
 }
Beispiel #14
0
        public void TryAnsyncReceiveMessage(int bufferSize, string tag)
        {
            DebugQy.LogTag("<<<<<<< REV MSG IN CLIENT <<<<<<<", "↓↓↓↓↓↓ [ in ][" + tag + ":" + bufferSize + "]↓↓↓↓↓↓ ", "#3C9553FF");
            DebugQy.LogTag("m_ReceiveMessage", " ---- in ---- ", "#3C9553FF");
            ISocketRecEventArgs recEventArgs = new RecEventArgs();

            recEventArgs.NeedRecvBufferSize = bufferSize;
            recEventArgs.Tag = tag;
            SocketAnsynParam stateParam = new SocketAnsynParam();

            stateParam.workSocket     = m_clientSocket;
            stateParam.transEventArgs = recEventArgs;
            m_ReceiveMessage(stateParam);
        }
Beispiel #15
0
 public SndToMasterData(string token_param, string gameId_param, string[] macOrDevice_param, DEVICED_TYPD deviceType)
 {
     try
     {
         m_token      = token_param;
         m_gameId     = gameId_param;
         m_socketType = ((int)SOCKET_TYPE.SOCKET).ToString();
         m_deviceType = ((int)deviceType).ToString();
         m_deviceId   = ChosseDevice(deviceType, macOrDevice_param);
     }
     catch (Exception ee)
     {
         DebugQy.LogWarning("SndToMasterData():There is a wrong operation :" + ee.Message);
     }
 }
Beispiel #16
0
        private bool m_GetIntFromStrWith_SCALE_OF_BYTE_SYSTEM(string fromStr, out int targetValue)
        {
            bool _n_tryPaseSuc = false;

            targetValue = 0;
            for (int idex = 0; idex < HEAD_DATA_NUMB; ++idex)
            {
                int tempValue;
                _n_tryPaseSuc = int.TryParse(fromStr.Substring(HEAD_DATA_UNIT * idex, HEAD_DATA_UNIT), out tempValue);
                if (!_n_tryPaseSuc)
                {
                    return(false);
                }
                int fourInt = tempValue * (int)Math.Pow(SCALE_OF_BYTE_SYSTEM, HEAD_DATA_NUMB - 1 - idex);
                targetValue += fourInt;
            }
            DebugQy.Log("Receive Head  4_Bytes: " + targetValue);
            return(true);
        }
Beispiel #17
0
        private void m_SocketSendEventHandle(COMPLETE_OR_FAILED isComplete, string message)
        {
            DebugQy.LogTag("【LAM】m_SocketSendEventHandle", "SND CALL BACK:" + message);
            switch (isComplete)
            {
            case COMPLETE_OR_FAILED.DEFAULT:
                DebugQy.LogError("【LAM】m_SocketSendEventHandle" + "---SND CALL BACK:" + message);
                break;

            case COMPLETE_OR_FAILED.COMPLETE:
                //socket数据处理器直接处理数据
                break;

            case COMPLETE_OR_FAILED.FAILED:
                //发送失败逻辑处理
                m_LinkFailedEventTrigger((int)LINK_STATUS_CODE.SOCKET_SND_F);
                break;
            }
        }
Beispiel #18
0
        private void m_SocketConnectedEventHandle(COMPLETE_OR_FAILED isComplete, string message)
        {
            DebugQy.LogTag("【LAM】m_SocketConnectedEventHandle", "---CON CALL BACK:" + message);
            switch (isComplete)
            {
            case COMPLETE_OR_FAILED.DEFAULT:
                DebugQy.LogError("【LAM】m_SocketConnectedEventHandle" + "---CON CALL BACK:" + message);
                break;

            case COMPLETE_OR_FAILED.COMPLETE:
                m_SocketClientController.ReceiveMessage();
                m_PushRoomVerification();
                break;

            case COMPLETE_OR_FAILED.FAILED:
                m_LinkFailedEventTrigger((int)LINK_STATUS_CODE.SOCKET_CON_F);
                break;
            }
        }
Beispiel #19
0
        private void m_BenginReceive(ISocketQy receiveObj, HEAD_BODY_PACKET choosePackage, int bufferSize)
        {
            switch (choosePackage)
            {
            case HEAD_BODY_PACKET.HEAD:
                DebugQy.Log("start receive HEAD :-------- thread.waitOne! ↓↓↓↓↓");
                receiveObj.TryAnsyncReceiveMessage(bufferSize, "HEAD");
                break;

            case HEAD_BODY_PACKET.BODY:
                DebugQy.Log("start receive BODY :-------- thread.waitOne! ↓↓↓↓↓");
                receiveObj.TryAnsyncReceiveMessage(bufferSize, "BODY");
                break;

            default:
                break;
            }
            m_recEventWaitHandle.WaitOne();
        }
Beispiel #20
0
        private void m_ReceiveHeadDataCallBack(ISocketQy sender, ISocketRecEventArgs args)
        {
            int currentBufferSize = args.NeedRecvBufferSize;

            if (currentBufferSize != HEAD_BUFFER_SIZE)
            {
                DebugQy.LogWarning("m_ReceiveHeadDataCallBack(): rec buffer size != 'HEAD_BUFFER_SIZE' . Please check your operate in receive.");
                if (RecMsgFailedEvent != null)
                {
                    RecMsgFailedEvent(sender, args);
                }
                DebugQy.LogWarning("'I Has stop your receive function !' ------- from writer. ");
                StopReceiveMessage();
                return;
            }
            string responseStr = Encoding.UTF8.GetString(args.ReceiveBuffer, 0, args.NeedRecvBufferSize);

            DebugQy.LogTag("HeadBodyTcpProtocol", "'HEAD_PACKAGE' has received. value of the package is :[" + responseStr + "]");
            int  nextBufferSize;
            bool isSuccess = m_GetIntFromStrWith_SCALE_OF_BYTE_SYSTEM(responseStr, out nextBufferSize);

            if (!isSuccess)
            {
                DebugQy.LogWarning("m_ReceiveHeadDataCallBack():the 'HeadBuffer' from sender is not a appoint value.\n"
                                   + "HeadBuffer to string :---." + responseStr + ".---");
                if (RecMsgFailedEvent != null)
                {
                    RecMsgFailedEvent(sender, args);
                }
                StopReceiveMessage();
                DebugQy.LogWarning("'I Has stop your receive function !' ------- from writer.");
            }
            else
            {
                DebugQy.LogTag("HeadBodyTcpProtocol", "'HEAD_PACKAGE' say next body size is:[" + nextBufferSize + "]");
                m_nextHeadOrBody  = HEAD_BODY_PACKET.BODY;
                m_nextPackageSize = nextBufferSize;
                m_recEventWaitHandle.Set();
                DebugQy.LogTag("HeadBodyTcpProtocol", "start receive [HEAD] :-------- thread.set      ↑↑↑↑↑\n ");
            }
        }
Beispiel #21
0
        private void m_RequestComleteCallBack(object sender, WebRequestArgsQy eventArgs)
        {
            DebugQy.Log("Request CallBack .");
            bool isMesRight = m_datahandle.WebDataHandle(eventArgs.Message, out m_masterMsg);

            if (isMesRight)
            {
                m_deviceId = m_masterMsg.deviceId;
                m_DataEventTrigger(DATA_STATUS_CODE.DATA_BUILD_ROOM_T,
                                   "Build room success.: your device:" + m_deviceId + "\n"
                                   + "RoomId : " + m_masterMsg.roomId + "\n"
                                   + "gameSign : " + m_masterMsg.gameSign);
                //主控回调数据正确,可触发成功事件
                StartSocketNetWork(m_masterMsg.WMIp, int.Parse(m_masterMsg.WMPort));
            }
            else
            {
                //主控回调数据错误,可触发失败事件
                m_DataEventTrigger(DATA_STATUS_CODE.DATA_BUILD_ROOM_F, "Build room failed : " + eventArgs.Message);
            }
        }
Beispiel #22
0
        public SocketClientController(CLIENT_SOCKET_TYPE socketType, SOCKET_DATA_PROTOCOL protocolType)
        {
            //链接选择:未来改枚举
            switch (socketType)
            {
            case CLIENT_SOCKET_TYPE.TCP:
                m_clientSocket = new ClientSocket();
                break;

            case CLIENT_SOCKET_TYPE.UDP:
                break;

            default:
                break;
            }
            if (m_clientSocket == null)
            {
                DebugQy.LogError("m_clientSocket is null.");
            }
            //链接事件
            m_clientSocket.AnsyncConnectTo_Complete_Event += m_StartConnectedCompleteCallBack;
            m_clientSocket.AnsyncConnectTo_Failed_Event   += m_StartConnectedFailedCallBack;
            //协议注册:未来改枚举
            switch (protocolType)
            {
            case SOCKET_DATA_PROTOCOL.HEAD_BODY:
                m_transProtocol = new HeadBodyTcpProtocol();
                break;

            default:
                break;
            }
            m_transProtocol.SetTargetSocket(m_clientSocket);
            //协议事件
            m_transProtocol.SendMsgCompleteEvent += m_ProtocolSendCompleteCallback;
            m_transProtocol.SendMsgFailedEvent   += m_ProtocolSendFailedCallback;
            m_transProtocol.RecMsgCompleteEvent  += m_ProtocolRecvCompleteCallback;
            m_transProtocol.RecMsgFailedEvent    += m_ProtocolRecvFailedCallback;
        }
Beispiel #23
0
        /// <summary>
        /// 事件选择器
        /// </summary>
        /// <param name="sender">私有变量m_SocketClientController</param>
        /// <param name="args">应用层参数</param>
        private void m_SocketEventFirCallBack(object sender, SocketClieCtrlEventArgs args)
        {
            switch (args.EventType)
            {
            case EVENT_TYPE.DEFAULT:
                DebugQy.LogError("【LAM】m_SocketSendEventHandle" + "EVENT HANDLE:");
                break;

            case EVENT_TYPE.CONNECT:
                m_SocketConnectedEventHandle(args.IsComplete, args.Message);
                break;

            case EVENT_TYPE.SEND:
                m_SocketSendEventHandle(args.IsComplete, args.Message);
                break;

            case EVENT_TYPE.RECEIVE:
                m_SocketReceiveEventHandle(args.IsComplete, args.Message);
                break;

            default:
                break;
            }
        }
Beispiel #24
0
 public void ContinueReceiveMsg()
 {
     if (m_tgWorkSocket == null)
     {
         DebugQy.LogWarning("Jisight_Tcp_BeginReceive(): your param is null ,check it please.");
         return;
     }
     if (m_recMsgThread == null)
     {
         ThreadStart threadstart = new ThreadStart(
             () =>
         {
             while (true)
             {
                 if (m_tgWorkSocket != null)
                 {
                     m_recEventWaitHandle.Reset();
                     m_BenginReceive(m_tgWorkSocket, m_nextHeadOrBody, m_nextPackageSize);
                 }
                 else
                 {
                     DebugQy.LogWarning("'receiveObj' in Jisight_Tcp_BeginReceive is null."
                                        + "So stop receive message from 'receiveObj'");
                     break;
                 }
             }
         });
         m_recMsgThread = new Thread(threadstart);
     }
     if (m_recMsgThread.IsAlive)
     {
         DebugQy.LogWarning("Receive funcion is working.Don't use this function again please !");
         return;
     }
     m_recMsgThread.Start();
 }
Beispiel #25
0
        public WebEasyHttpQy(WEB_REQUEST_TYPE webNetType       = WEB_REQUEST_TYPE.HTTP,
                             WEB_DATA_PROTOCOL webDataProtocol = WEB_DATA_PROTOCOL.ORIGINAL)
        {
            switch (webNetType)
            {
            case WEB_REQUEST_TYPE.HTTP:
                m_WebRequest = new HttpWebRequestQy();
                break;

            default:
                DebugQy.LogError("'WEB_REQUEST_TYPE' can not clear. ");
                break;
            }
            switch (webDataProtocol)
            {
            case WEB_DATA_PROTOCOL.ORIGINAL:
                m_protocol = new WebKeepOrigDataProtocol();
                break;

            default:
                DebugQy.LogError("'WEB_DATA_PROTOCOL' can not clear. ");
                break;
            }
        }
Beispiel #26
0
 /// <summary>
 /// 协议发送事件失败回调
 /// </summary>
 /// <param name="sender">触发该事件的SocketQY</param>
 /// <param name="eventArgs">参数</param>
 private void m_ProtocolSendCompleteCallback(ISocketQy sender, ISocketSndEventArgs eventArgs)
 {
     DebugQy.LogTag("ClientController", "Send Complete CallBack:" + eventArgs.ErrMessage);
     m_FirSomeEvent(EVENT_TYPE.SEND, COMPLETE_OR_FAILED.COMPLETE, eventArgs.ErrMessage);
 }
Beispiel #27
0
 /// <summary>
 /// 非协议内连接事件回调
 /// </summary>
 /// <param name="sender">触发该事件的SocketQY</param>
 /// <param name="eventArgs">参数</param>
 private void m_StartConnectedFailedCallBack(ISocketQy sender, ISocketTransEventArgs eventArgs)
 {
     DebugQy.LogTag("ClientController", "StartConnectedFailedCallBack:" + eventArgs.ErrMessage);
     m_FirSomeEvent(EVENT_TYPE.CONNECT, COMPLETE_OR_FAILED.FAILED, eventArgs.ErrMessage);
 }
Beispiel #28
0
 /// <summary>
 /// 协议发送事件失败回调
 /// </summary>
 /// <param name="sender">触发该事件的SocketQY</param>
 /// <param name="eventArgs">参数</param>
 private void m_ProtocolRecvFailedCallback(ISocketQy sender, ISocketRecEventArgs eventArgs)
 {
     DebugQy.LogTag("ClientController", "Recv Failed CallBack:" + eventArgs.ErrMessage);
     m_FirSomeEvent(EVENT_TYPE.RECEIVE, COMPLETE_OR_FAILED.FAILED, eventArgs.ErrMessage);
 }
Beispiel #29
0
        private void m_Post(byte[] postBuffer)
        {
            HttpWebPostArgs _postEventArgs = new HttpWebPostArgs();
            string          errorMessage   = string.Empty;
            FIRING_D_C_F    _firEventType  = FIRING_D_C_F.DEFAULT;

            DebugQy.Log("m_Post(): buffer message in.");
            m_httpRequest.KeepAlive = false;
            m_httpRequest.Method    = "POST";
            //m_httpRequest.ContentType = "application/x-www-form-urlencoded";
            m_httpRequest.ContentType = "application/json";
            Stream _writer;

            _writer = m_httpRequest.GetRequestStream(); //任何尝试访问该方法时,不在子代类中重写该方法时:会引发NotImplementedException

            try
            {
                _writer.Write(postBuffer, 0, postBuffer.Length);
                _writer.Close();
                DebugQy.Log("m_Post(): buffer has posted.");
            }
            catch (ArgumentNullException ee)
            {
                errorMessage = "---  ArgumentNullException  --- :"
                               + "buffer is null"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (ArgumentOutOfRangeException ee)
            {
                errorMessage = "---  ArgumentOutOfRangeException  --- :"
                               + "offset 或 count 为负。"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (ArgumentException ee)
            {
                errorMessage = "---  ArgumentException  --- :"
                               + "总和 offset 和 count 大于缓冲区长度。"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (IOException ee)
            {
                errorMessage = "---  IOException  --- :"
                               + "将出现 I / O 错误,如找不到指定的文件。"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (NotSupportedException ee)
            {
                errorMessage = "---  NotSupportedException  --- :"
                               + "流不支持写入。"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (Exception ee)
            {
                errorMessage = "---  Unknown exception  --- :"
                               + "Firing other unknown exception !!!!!!"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            if (_firEventType == FIRING_D_C_F.FIR_FAILED)
            {
                _postEventArgs.SetErrMessage(errorMessage);
                m_PostEventFiring(_firEventType, _postEventArgs, "m_Post");
                return;
            }
            HttpWebResponse _httpResponse   = m_httpRequest.GetResponse() as HttpWebResponse;
            Stream          _responseStream = _httpResponse.GetResponseStream();

            try
            {
                ///TODO:2016/12/19这句话报错,考虑后期流媒体怎么处理!!!!!
                ///------------解决方案:转码一次,后期考虑字节的直接操作,性能 性能 性能!!!;
                /// int length = (int)_responseStream.Length;
                StreamReader _reader = new StreamReader(_responseStream);
                string       aa      = _reader.ReadToEnd();
                byte[]       buffer  = Encoding.UTF8.GetBytes(aa);
                DebugQy.Log("RquestMessage buffer length :" + buffer.Length);
                _responseStream.Close();
                _postEventArgs.SetBuffer(buffer);
                _firEventType = FIRING_D_C_F.FIR_COMPLETE;
                errorMessage  = "---  no mistake  ---";
            }
            catch (ArgumentNullException ee)
            {
                errorMessage = "---  ArgumentNullException  --- :"
                               + "buffer is null"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (ArgumentOutOfRangeException ee)
            {
                errorMessage = "---  ArgumentOutOfRangeException  --- :"
                               + "offset 或 count 为负。"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (ArgumentException ee)
            {
                errorMessage = "---  ArgumentException  --- :"
                               + "总和 offset 和 count 大于缓冲区长度。"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (IOException ee)
            {
                errorMessage = "---  IOException  --- :"
                               + "将出现 I / O 错误,如找不到指定的文件。"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (NotSupportedException ee)
            {
                errorMessage = "---  NotSupportedException  --- :"
                               + "流不支持读取。"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (Exception ee)
            {
                errorMessage = "---  Unknown exception  --- :"
                               + "Firing other unknown exception !!!!!!"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            _postEventArgs.SetErrMessage(errorMessage);
            m_PostEventFiring(_firEventType, _postEventArgs, "m_ReceiveMsgCallBack");
        }
Beispiel #30
0
 public void SendMessage(string sndMsg)
 {
     DebugQy.LogTag("SocketClientController", "Ready to send in SocketController :" + sndMsg);
     byte[] buffer = Encoding.UTF8.GetBytes(sndMsg);
     m_transProtocol.SendMessage(buffer);
 }