Example #1
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);
            }
        }
Example #2
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);
        }
Example #3
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;
            }
        }
Example #4
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);
     }
 }
Example #5
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 ");
            }
        }
Example #6
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();
 }
Example #7
0
        /// <summary>
        /// 启动 Look At Me 服务
        /// </summary>
        /// <param name="url">接口Url</param>
        /// <param name="token">调用方的授权码</param>
        /// <param name="gameId">游戏不同,该值由游戏制作方确定</param>
        /// <param name="deviceIds">设备编号,如果不填自动获取 MAC</param>
        public void Start(string token, string gameId, string[] deviceIds = null)
        {
            string _url = "";

            m_token  = token;
            m_gameId = gameId;
            switch (m_netOption)
            {
            case NET_OPTION.LAN:
                _url = POST_URL_LAN;
                break;

            case NET_OPTION.WAN:
                _url = POST_URL_WAN;
                break;
            }
            SndToMasterData sndMessage = null;

            #region   若填写deviceIds,则以填写的值为准,否则自动获取该机器Mac;
            if (deviceIds == null || deviceIds.Length == 0)
            {
                string[] _macOrDevice = GetMacAdress.GetAllMacs();
                sndMessage = new SndToMasterData(token,
                                                 gameId,
                                                 _macOrDevice,
                                                 DEVICED_TYPD.MACS);
            }
            else
            {
                switch (deviceIds.Length)
                {
                case 1:
                    sndMessage = new SndToMasterData(m_token,
                                                     m_gameId,
                                                     deviceIds,
                                                     DEVICED_TYPD.DEVICE_ONE);
                    break;

                case 2:
                    sndMessage = new SndToMasterData(m_token,
                                                     m_gameId,
                                                     deviceIds,
                                                     DEVICED_TYPD.DEVICE_TWO);
                    break;

                case 3:
                    sndMessage = new SndToMasterData(m_token,
                                                     m_gameId,
                                                     deviceIds,
                                                     DEVICED_TYPD.DEVICE_THREE);

                    break;

                default:
                    sndMessage = new SndToMasterData(m_token,
                                                     m_gameId,
                                                     deviceIds,
                                                     DEVICED_TYPD.DEVICE_ONE);
                    DebugQy.LogWarning("deviceIds is wrong.");
                    string argStr = "deviceIds param is wrong.";
                    m_DataEventTrigger(DATA_STATUS_CODE.ERROR_TRIGGER_CODE, argStr);
                    return;
                }
            }
            #endregion
            string msg = JsonToolsQy.ToJson(sndMessage);
            m_PostRequest(_url, msg);
        }
Example #8
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;
            }
        }
Example #9
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");
        }
Example #10
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");
        }
Example #11
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");
        }
Example #12
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:");
        }
Example #13
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);
        }