Пример #1
0
        public void UpdateRecvAsync()
        {
            if (m_netTcpClient == null)
            {
                return;
            }

            CNetPacket netPacket = null;

            while (m_netTcpClient.RecvAsync(out netPacket))
            {
                switch (netPacket.m_packetType)
                {
                case CNetPacket.EType.CONNECTION_REQUEST_SUCCESS:
                    if (m_connectSuccess != null)
                    {
                        UnityUtility.CTrace.Singleton.debug("连接成功[{0}]", netPacket.m_packetType);
                        m_connectSuccess();
                    }
                    break;

                case CNetPacket.EType.CONNECTION_REQUEST_FAILED:
                    if (m_connectFail != null && !m_isClose)
                    {
                        m_isClose = true;
                        UnityUtility.CTrace.Singleton.debug("连接失败[{0}]", netPacket.m_packetType);
                        m_connectFail();
                    }
                    break;

                case CNetPacket.EType.CONNECTION_LOST:
                case CNetPacket.EType.CONNECTION_CLOSE:
                case CNetPacket.EType.CONNECTION_CLOSE_ENCRYPT:
                case CNetPacket.EType.CONNECTION_CLOSE_COMPRESS:
                    if (m_netLinkClose != null && !m_isClose)
                    {
                        m_isClose = true;
                        UnityUtility.CTrace.Singleton.debug("连接关闭[{0}]", netPacket.m_packetType);
                        m_netLinkClose();
                    }
                    break;

                case CNetPacket.EType.CONNECTION_RECV_PACKET:
                    if (m_recvAsync != null)
                    {
                        m_recvAsync(netPacket.m_buffer);
                    }
                    break;

                case CNetPacket.EType.NULL:
                default:
                {
                    ;
                }
                break;
                }
            }
        }
Пример #2
0
        private void _PushPacket(UnityUtility.CBuffer buffer)
        {
            CNetPacket packet = new CNetPacket();

            packet.m_packetType = CNetPacket.EType.CONNECTION_RECV_PACKET;
            packet.m_peer       = m_socket;
            packet.m_buffer     = buffer;

            lock (m_packetQueue)
            {
                m_packetQueue.Enqueue(packet);
            }
        }
Пример #3
0
        // 向Network Manager的队列传递内部消息
        private void _PushPacket(CNetPacket.EType packetType, string exception)
        {
            CNetPacket packet = new CNetPacket();

            packet.m_packetType = packetType;
            packet.m_peer       = m_socket;
            packet.m_error      = exception;

            lock (m_packetQueue)
            {
                m_packetQueue.Enqueue(packet);
            }
        }
Пример #4
0
 // 异步接收消息
 public bool RecvAsync(out CNetPacket netPacket)
 {
     netPacket = null;
     if (m_packetQueue.Count <= 0)
     {
         return(false);
     }
     lock (m_packetQueue)
     {
         netPacket = (CNetPacket)m_packetQueue.Dequeue();;
     }
     return(true);
 }