Exemplo n.º 1
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;
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
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;
            }
        }
Exemplo n.º 5
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;
            }
        }
Exemplo n.º 6
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;
            }
        }
Exemplo n.º 7
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");
        }
Exemplo n.º 8
0
 private void m_SendMessageFaliedCallBack(ISocketQy sender, ISocketSndEventArgs evetArgs)
 {
     DebugQy.LogTag("HeadBodyTcpProtocol", "Failed Call Back in 'Protocol'.");
     if (SendMsgFailedEvent != null)
     {
         SendMsgFailedEvent(sender, evetArgs);
     }
 }
Exemplo n.º 9
0
 public void Dispose()
 {
     DebugQy.LogTag("ClientSocket", "Disposed !!!!!!!!", "#BB7979FF");
     if (m_clientSocket.Connected)
     {
         m_clientSocket.Shutdown(SocketShutdown.Both);
         m_clientSocket.Close();
     }
 }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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;
            }
        }
Exemplo n.º 12
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;
            }
        }
Exemplo n.º 13
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 ");
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// 主控服务器返回值的数据解析
        /// </summary>
        /// <param name="message">返回数据</param>
        /// <param name="msgFromMaster">外部应用数据</param>
        /// <returns></returns>
        public bool WebDataHandle(string message, out MsgFromMaster msgFromMaster)
        {
            DebugQy.LogTag("WebDataHandle():--- in ---", message);
            msgFromMaster = new MsgFromMaster();
            JsonDataQy _jsonData = JsonToolsQy.GetJsonData(message);

            if (_jsonData["status"] != null)
            {
                if (_jsonData["status"].ToString() != "0")
                {
                    DebugQy.LogTag("status:", _jsonData["status"] + "   WebNet status is wrong.");
                    return(false);
                }
                else
                {
                    //待扩展其他错误(非“0”)状态码
                }
            }
            else
            {
                DebugQy.LogTag("status:", _jsonData["status"] + "   WebNet status is not finger .");
                return(false);
            }
            DebugQy.LogTag("status:", _jsonData["status"] + "   WebNet status is right.");
            if (_jsonData["message"]["WMIp"] != null)
            {
                msgFromMaster.WMIp = _jsonData["message"]["WMIp"].ToString();
            }
            else
            {
                DebugQy.LogWarning("WebDataHandle(): Receive[message][WMIp] is null . So it's use default value.");
            }
            if (_jsonData["message"]["WMPort"] != null)
            {
                msgFromMaster.WMPort = _jsonData["message"]["WMPort"].ToString();
            }
            else
            {
                DebugQy.LogWarning("WebDataHandle(): Receive[message][WMPort] is null . So it's use default value.");
            }
            if (_jsonData["message"]["roomId"] != null)
            {
                msgFromMaster.roomId = _jsonData["message"]["roomId"].ToString();
            }
            else
            {
                DebugQy.LogWarning("WebDataHandle(): Receive[message][roomId] is null . So it's use default value.");
            }
            if (_jsonData["message"]["gameSign"] != null)
            {
                msgFromMaster.gameSign = _jsonData["message"]["gameSign"].ToString();
            }
            else
            {
                DebugQy.LogWarning("WebDataHandle(): Receive[message][gameSign] is null . So it's use default value.");
            }
            if (_jsonData["message"]["deviceId"] != null)
            {
                msgFromMaster.deviceId = _jsonData["message"]["deviceId"].ToString();
            }
            else
            {
                DebugQy.LogWarning("WebDataHandle(): Receive[message][deviceId] is null . So it's use default value.");
            }

            DebugQy.LogTag("WebDataHandle():--- out ---", message);
            return(true);
        }
Exemplo n.º 15
0
 public void TryAnsyncSendMessage(byte[] buffer, string tag)
 {
     DebugQy.LogTag(">>>>>>> SEN MSG IN CLIENT >>>>>>>", "↓↓↓↓↓↓ [ in ][" + tag + ":" + buffer.Length + "]↓↓↓↓↓↓ ", "#3487E8FF");
     m_SendMessage(buffer, tag);
 }
Exemplo n.º 16
0
        private void m_SendMessage(byte[] buffer, string tag, SocketFlags flags = SocketFlags.None)
        {
            DebugQy.LogTag("m_SendMessage", " ---- in ---- ", "#3487E8FF");
            FIRING_D_C_F        firEventType = FIRING_D_C_F.DEFAULT;
            string              errorMessage = string.Empty;
            ISocketSndEventArgs sndEventArgs = new SndEventArgs();

            sndEventArgs.SetBuffer(buffer);
            sndEventArgs.SetTag(tag);
            SocketAnsynParam stateParam = new SocketAnsynParam();

            stateParam.workSocket     = m_clientSocket;
            stateParam.transEventArgs = sndEventArgs;
            try
            {
                SocketError socketErrorCode;
                m_clientSocket.BeginSend(sndEventArgs.SendBuffer,
                                         0,
                                         sndEventArgs.BufferSize,
                                         flags,
                                         out socketErrorCode,
                                         new AsyncCallback(m_SendMsgCallBack),
                                         stateParam
                                         );
                if (socketErrorCode != SocketError.Success)
                {
                    DebugQy.LogWarning("[SEND MESAGE] Socket error : [" + socketErrorCode.ToString() + "] ,Check it !!!!!!!");
                }
            }
            catch (ArgumentNullException ee)
            {
                errorMessage = "×××  ArgumentNullException  ×××:"
                               + "buffers 为 null。"
                               + ee.Message;
                firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (ArgumentException ee)
            {
                errorMessage = "×××  ArgumentException  ×××:"
                               + "buffers 为空。"
                               + 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 (Exception ee)
            {
                errorMessage = "×××  Unknown exception  ××× :"
                               + "Firing other unknown exception !!!!!!"
                               + ee.Message;
                firEventType = FIRING_D_C_F.FIR_FAILED;
            }

            sndEventArgs.SetErrMessage(errorMessage);
            m_SendMessageEventFiring(firEventType, sndEventArgs, "m_SendMessage:");
        }
Exemplo n.º 17
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);
 }
Exemplo n.º 18
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);
 }
Exemplo n.º 19
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);
 }
Exemplo n.º 20
0
        private void m_SendMsgCallBack(IAsyncResult asyncResult)
        {
            DebugQy.LogTag("m_SendMsgCallBack", " ---- in ---- ", "#3487E8FF");
            string              errorMessage = string.Empty;
            SocketAnsynParam    ansynParam   = asyncResult.AsyncState as SocketAnsynParam;
            ISocketSndEventArgs sndEventArgs = ansynParam.transEventArgs as ISocketSndEventArgs;
            FIRING_D_C_F        firEventType = FIRING_D_C_F.DEFAULT;

            try
            {
                SocketError socketErrorCode;
                int         sndBufferSize = ansynParam.workSocket.EndSend(asyncResult, out socketErrorCode);
                if (socketErrorCode != SocketError.Success)
                {
                    DebugQy.LogWarning("[SEND MESAGE CALLBACK] Socket error : [" + socketErrorCode.ToString() + "]");
                }
                if (sndBufferSize == sndEventArgs.BufferSize)
                {
                    errorMessage = "√√√ no mistake √√√ SendComplete buffer lenth is :[" + sndBufferSize + "]";
                    firEventType = FIRING_D_C_F.FIR_COMPLETE;
                }
                else
                {
                    DebugQy.LogWarning("Real 'SEND' buffer != needSize   NeedSndLengrh :[" + sndEventArgs.BufferSize + "]*-*-*-*-*");
                    DebugQy.LogWarning("Real 'SEND' buffer != needSize   RealSndLengrh :[" + sndBufferSize + "]*-*-*-*-*");
                    DebugQy.LogWarning("源:." + Encoding.UTF8.GetString(sndEventArgs.SendBuffer, 0, sndEventArgs.BufferSize) + ".");
                    errorMessage = "×××  receive bytes size is wrong.  ××× :"
                                   + "需接收数据与接收数据字节不匹配!";
                    DebugQy.LogWarning(errorMessage);
                    firEventType = FIRING_D_C_F.FIR_FAILED;
                    //TODO:返回值校验的逻辑处理:查看Socket底层后再做补充 !!!
                }
            }
            catch (ArgumentNullException ee)
            {
                errorMessage = "×××  ArgumentNullException  ×××:"
                               + "asyncResult 为 null。"
                               + ee.Message;
                firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (ArgumentException ee)
            {
                errorMessage = "×××  ArgumentException  ×××:"
                               + "BeginSend 方法调用后未返回 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  ×××"
                               + "先前为异步发送已调用过 EndSend。"
                               + 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;
            }
            sndEventArgs.SetErrMessage(errorMessage);
            m_SendMessageEventFiring(firEventType, sndEventArgs, "m_SendMsgCallBack");
            DebugQy.LogTag(">>>>>>> SEN MSG IN CLIENT >>>>>>>", "↑↑↑↑↑↑↑ [ out ][" + sndEventArgs.Tag + ":" + sndEventArgs.BufferSize + "]↑↑↑↑↑↑↑ ", "#3487E8FF");
        }
Exemplo n.º 21
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);
 }
Exemplo n.º 22
0
        private void m_SocketReceiveEventHandle(COMPLETE_OR_FAILED isComplete, string message)
        {
            DebugQy.LogTag("【LAM】m_SocketReceiveEventHandle", "REC CALL BACK:" + message);
            switch (isComplete)
            {
            case COMPLETE_OR_FAILED.DEFAULT:
                DebugQy.LogError("【LAM】m_SocketReceiveEventHandle" + "---REC CALL BACK:" + message);
                break;

            case COMPLETE_OR_FAILED.COMPLETE:
                ClearDataFormat _clearData;
                bool            _isSucc = m_datahandle.SocketStrDataHandle(message, out _clearData);
                //if (_clearData.Type != REV_MSG_TYPE.HEART_BEAT)
                //{
                //    DebugQy.LeoLog("<color=red>>>>>>>>:" + message + "</color>");
                //}
                if (_isSucc)
                {
                    switch (_clearData.Type)
                    {
                    case REV_MSG_TYPE.DEFAULT:
                        DebugQy.LogError("【LAM】case :0" + "---REC CALL BACK:" + message + "\n"
                                         + "type is not clear.");
                        break;

                    case REV_MSG_TYPE.HEART_BEAT:                              //20000 ---- 收到心跳信息
                        DebugQy.Log("【LAM】case :20000" + "HeatBeat:");
                        m_HeartBeatReturn(_clearData.Time);
                        return;

                    case REV_MSG_TYPE.ROOM_VERIFICATION_T:                      //21100 ---- 收到房间验证 正确
                        DebugQy.LogTag("【LAM】case :21100", "Room verification right.");
                        string codeStr = WEB_BASE_URL + "deviceId=" + m_deviceId + "&gameId=" + m_gameId + "&socketType=1";
                        m_isConnected = true;
                        m_DataEventTrigger(DATA_STATUS_CODE.DATA_ROOM_VERIFY_T, codeStr);
                        break;

                    case REV_MSG_TYPE.ROOM_VERIFICATION_F:                      //21101 ---- 收到房间验证 错误
                        DebugQy.LogTag("【LAM】case :21101", "Room verification wrong.");
                        m_DataEventTrigger(DATA_STATUS_CODE.DATA_ROOM_VERIFY_F, "Verification failed.");
                        break;

                    case REV_MSG_TYPE.AWARD_LIST_T:                             //21200 ---- 收到 奖励申请 正确
                        DebugQy.LogTag("【LAM】case :21200", "奖励申请 回复");
                        m_DataEventTrigger(DATA_STATUS_CODE.DATA_AWARD_LIST_T, _clearData.Msg);
                        break;

                    case REV_MSG_TYPE.AWARD_LIST_F:                             //21201 ---- 收到 奖励申请 错误
                        DebugQy.LogTag("【LAM】case :21201", "奖励申请 回复");
                        m_DataEventTrigger(DATA_STATUS_CODE.DATA_AWARD_LIST_F, "Request award list failed.");
                        break;

                    case REV_MSG_TYPE.ROOM_STATUS_T:                            //22000 ---- 房间状态推送 正确
                        DebugQy.LogTag("【LAM】case :22000", "房间状态 回复");
                        m_DataEventTrigger(DATA_STATUS_CODE.DATA_ROOM_STATUS_T, _clearData.Msg);
                        break;

                    case REV_MSG_TYPE.ROOM_STATUS_F:                            //22001 ---- 房间状态推送 错误
                        DebugQy.LogTag("【LAM】case :22001", "房间状态 回复");
                        m_DataEventTrigger(DATA_STATUS_CODE.DATA_ROOM_STATUS_F, "Push room status failed.");
                        break;

                    case REV_MSG_TYPE.SUMMARIZE_T:                              //22100 ---- 收到 排行榜 正确
                        DebugQy.LogTag("【LAM】case :22100", "汇总数据 回复");
                        m_DataEventTrigger(DATA_STATUS_CODE.DATA_SUMMARIZE_T, _clearData.Msg);
                        break;

                    case REV_MSG_TYPE.SUMMARIZE_F:                              //22101 ---- 收到 排行榜 错误
                        DebugQy.LogTag("【LAM】case :22101", "汇总数据 回复");
                        m_DataEventTrigger(DATA_STATUS_CODE.DATA_SUMMARIZE_F, "Push rank list failed.");
                        break;

                    case REV_MSG_TYPE.PC_H5_T:                                  //40000 ---- 用户数据 正确
                        DebugQy.LogTag("【LAM】case :40000", "用户数据 回复");
                        m_DataEventTrigger(DATA_STATUS_CODE.DATA_CUSTOM_MSG_T, _clearData.Msg);
                        break;

                    case REV_MSG_TYPE.PC_H5_F:                                  //40001 ---- 用户数据 错误
                        DebugQy.LogTag("【LAM】case :40001", "用户数据 回复");
                        m_DataEventTrigger(DATA_STATUS_CODE.DATA_CUSTOM_MSG_F, "Recv user message failed.");
                        break;

                    case REV_MSG_TYPE.H5_LINK_BROKEN:                                //23000 ---- H5 断链 链接
                        DebugQy.LogTag("【LAM】case :23000", "用户断开链接信息");
                        m_DataEventTrigger(DATA_STATUS_CODE.LINK_USER_BROKEN, _clearData.Msg);
                        break;

                    default:
                        DebugQy.LogWarning("【LAM】Can not clear the type");
                        break;
                    }
                }
                else
                {
                    DebugQy.LogWarning("m_SocketSendEventHandle: Some format is wrong.check the message :" + message);
                }
                break;

            case COMPLETE_OR_FAILED.FAILED:
                UnityEngine.Debug.Log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:" + message);
                //接收失败逻辑处理
                m_LinkFailedEventTrigger((int)LINK_STATUS_CODE.SOCKET_REV_F);
                break;
            }
        }
Exemplo n.º 23
0
        private void m_BeginConnect(EndPoint endPoint)
        {
            DebugQy.LogTag("<<<<<<< CON ENP IN CLIENT >>>>>>>", "*-*-*-*-*[ in ]*-*-*-*-*");

            FIRING_D_C_F        _firEventType = FIRING_D_C_F.DEFAULT;
            string              errorMessage  = string.Empty;
            ISocketConEventArgs _conEventArgs = new ConEventArgs();
            SocketAnsynParam    stateParam    = new SocketAnsynParam();

            stateParam.workSocket     = m_clientSocket;
            stateParam.transEventArgs = _conEventArgs;
            try
            {
                m_clientSocket.BeginConnect(endPoint,
                                            new AsyncCallback(m_ConnectCallBack),
                                            stateParam
                                            );
            }
            catch (ArgumentNullException ee)
            {
                errorMessage = "×××  ArgumentNullException  ××× :"
                               + "remoteEP is null. Error code :"
                               + 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 (SecurityException ee)
            {
                errorMessage = "×××  SecurityException  ××× :"
                               + "调用堆栈上部的调用方无权执行所请求的操作。"
                               + ee.Message;
                _firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (InvalidOperationException ee)
            {
                errorMessage = "×××  InvalidOperationException  ××× :"
                               + "Socket 为 Listen。"
                               + 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;
            }

            _conEventArgs.SetErrMessage(errorMessage);
            m_ConnectEventFiring(_firEventType, _conEventArgs, "m_BeginConnect");
        }
Exemplo n.º 24
0
        private void m_ReceiveMessage(SocketAnsynParam stateParam, SocketFlags flags = SocketFlags.None)
        {
            ISocketRecEventArgs recvEventArgs = stateParam.transEventArgs as ISocketRecEventArgs;

            string       errorMessage = string.Empty;
            FIRING_D_C_F firEventType = FIRING_D_C_F.DEFAULT;

            if (m_lastBuffer.Count >= recvEventArgs.NeedRecvBufferSize)              //当上一次剩余的缓存数据足够本次使用时
            {
                DebugQy.LogTag("m_ReceiveMessage", "need buffer size :[" + recvEventArgs.NeedRecvBufferSize + "]", "#3C9553FF");
                DebugQy.LogTag("m_ReceiveMessage", "last buffer length :[" + m_lastBuffer.Count + "]", "#3C9553FF");
                DebugQy.LogTag("m_ReceiveMessage", "so dont need begin receive .", "#3C9553FF");
                byte[] buffer = new byte[recvEventArgs.NeedRecvBufferSize];
                m_lastBuffer.CopyTo(0, buffer, 0, recvEventArgs.NeedRecvBufferSize);
                m_lastBuffer.RemoveRange(0, recvEventArgs.NeedRecvBufferSize);
                recvEventArgs.SetBuffer(buffer);
                errorMessage = "√√√ no mistake √√√ ";
                firEventType = FIRING_D_C_F.FIR_COMPLETE;
            }
            else
            {
                try
                {
                    SocketError socketErrorCode;
                    m_clientSocket.BeginReceive(m_tempRecvBuffer,
                                                0,
                                                m_tempRecvBuffer.Length,
                                                flags,
                                                out socketErrorCode,
                                                new AsyncCallback(m_ReceiveMsgCallBack),
                                                stateParam
                                                );
                    if (socketErrorCode != SocketError.Success)
                    {
                        DebugQy.LogWarning("[RECV MESAGE] Socket error : [" + socketErrorCode.ToString() + "] ,Check it !!!!!!!");
                    }
                }
                catch (ArgumentNullException ee)
                {
                    errorMessage = "×××  ArgumentNullException  ×××:"
                                   + "buffers 为 null。"
                                   + 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 (ArgumentOutOfRangeException ee)
                {
                    errorMessage = "×××  ArgumentOutOfRangeException  ×××:"
                                   + "offset 小于 0。-或 -offset 大于 buffer 的长度。-或 -size 小于 0。-或 -size 大于 buffer 的长度减去 offset 参数的值。"
                                   + 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;
                }
            }
            recvEventArgs.SetErrMessage(errorMessage);
            m_ReceiveMessageEventFiring(firEventType, recvEventArgs, "m_ReceiveMessage");
        }
Exemplo n.º 25
0
        private void m_ReceiveMsgCallBack(IAsyncResult asyncResult)
        {
            DebugQy.LogTag("m_ReceiveMsgCallBack", " ---- in ---- ", "#3C9553FF");
            FIRING_D_C_F        firEventType = FIRING_D_C_F.DEFAULT;
            string              errorMessage = string.Empty;
            SocketAnsynParam    ansynParam   = asyncResult.AsyncState as SocketAnsynParam;
            ISocketRecEventArgs recEventArgs = ansynParam.transEventArgs as ISocketRecEventArgs;

            try
            {
                SocketError socketErrorCode;
                int         realRevbufSize = ansynParam.workSocket.EndReceive(asyncResult, out socketErrorCode);
                if (socketErrorCode != SocketError.Success)
                {
                    DebugQy.LogWarning("[RECV MESAGE] Socket error : [" + socketErrorCode.ToString() + "] ,Check it !!!!!!!");
                }

                if (realRevbufSize == 0)
                {
                    errorMessage = "×××  receive bytes size is '0'  ××× :"
                                   + "远程链接已调用shutDown\\close.";
                    firEventType = FIRING_D_C_F.FIR_FAILED;
                }
                else
                {
                    DebugQy.LogTag("m_ReceiveMsgCallBack", "Current receive buffer length :[" + realRevbufSize + "]", "#3C9553FF");
                    byte[] bytes = new byte[realRevbufSize];
                    Buffer.BlockCopy(m_tempRecvBuffer, 0, bytes, 0, realRevbufSize);
                    m_lastBuffer.AddRange(bytes);

                    if (m_lastBuffer.Count >= recEventArgs.NeedRecvBufferSize)
                    {
                        DebugQy.LogTag("m_ReceiveMsgCallBack", "Real 'RECV' buffer > needSize   NeedRecLength :[" + recEventArgs.NeedRecvBufferSize + "]", "#3C9553FF");
                        DebugQy.LogTag("m_ReceiveMsgCallBack", "Real 'RECV' buffer > needSize   RealRecLengrh :[" + m_lastBuffer.Count + "]", "#3C9553FF");
                        byte[] buffer = new byte[recEventArgs.NeedRecvBufferSize];
                        m_lastBuffer.CopyTo(0, buffer, 0, recEventArgs.NeedRecvBufferSize);
                        m_lastBuffer.RemoveRange(0, recEventArgs.NeedRecvBufferSize);
                        recEventArgs.SetBuffer(buffer);
                        errorMessage = "√√√ no mistake √√√ ";
                        firEventType = FIRING_D_C_F.FIR_COMPLETE;
                    }
                    else if (m_lastBuffer.Count < recEventArgs.NeedRecvBufferSize)
                    {
                        DebugQy.LogTag("m_ReceiveMsgCallBack", "Real 'RECV' buffer < needSize   NeedRecLength :[" + recEventArgs.NeedRecvBufferSize + "]", "#3C9553FF");
                        DebugQy.LogTag("m_ReceiveMsgCallBack", "Real 'RECV' buffer < needSize   RealRecLengrh :[" + m_lastBuffer.Count + "]", "#3C9553FF");
                        m_ReceiveMessage(ansynParam);
                        return;
                    }
                }
            }
            catch (ArgumentNullException ee)
            {
                errorMessage = "×××  ArgumentNullException  ×××:"
                               + "asyncResult 为 null。"
                               + ee.Message;
                firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (ArgumentException ee)
            {
                errorMessage = "×××  ArgumentException  ×××:"
                               + "方法调用后未返回 asyncResult。"
                               + 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  ×××:"
                               + "先前曾为异步读取调用过 EndReceive。"
                               + ee.Message;
                firEventType = FIRING_D_C_F.FIR_FAILED;
            }
            catch (SocketException ee)
            {
                errorMessage = "×××  SocketException  ×××:"
                               + " 试图访问套接字时发生错误。"
                               + 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("<<<<<<< REV MSG IN CLIENT <<<<<<<", "↑↑↑↑↑↑↑ [ out ][" + recEventArgs.Tag + ":" + recEventArgs.NeedRecvBufferSize + "]↑↑↑↑↑↑↑ ", "#3C9553FF");
            recEventArgs.SetErrMessage(errorMessage);
            m_ReceiveMessageEventFiring(firEventType, recEventArgs, "m_ReceiveMsgCallBack");
        }