Exemplo n.º 1
0
        public void Update()
        {
            //	if (mListener == null)
            //		return;

            lock (mLock)
            {
                if (mNetState == ENetState.ES_Connecting)
                {
                    mConnectWaitTime += (int)(UnityEngine.Time.deltaTime * 1000.0f);
                    if (mConnectWaitTime > mConnectMaxWaitTime)
                    {
                        mNetState = ENetState.ES_Disconnect;

                        if (mSocket != null)
                        {
                            mSocket.Close();
                            mSocket = null;
                        }
                        //mListener.OnDisconnect(-1);
                    }
                }

                while (mReplyList.Count > 0)
                {
                    LinkedListNode <Reply> replyNode = mReplyList.First;
                    switch (replyNode.Value.Type)
                    {
                    case EReplyType.RT_Connected:
                    {
                        UnityEngine.Debug.Log("RT_Connected : Socket Connect Succeed");
                        connected = true;
#if false
                        twp.protocol.c2fep.ReqEncryptInfo reqEncryptInfo = new twp.protocol.c2fep.ReqEncryptInfo();
                        CBoard.Instance.send(reqEncryptInfo.ToBin());
#endif
                        break;
                    }

                    case EReplyType.RT_Disconnect:
                    {
                        UnityEngine.Debug.LogWarning("RT_Disconnect");
                        break;
                    }

                    case EReplyType.RT_DataReply:
                    {
                        //UnityEngine.Debug.LogWarning("RT_DataReply");
                        UnityEngine.Debug.Log("===packet header:  " + System.BitConverter.ToUInt16(replyNode.Value.Data.ToArray(), 0) + "===");

                        //处理消息
                        processStram(new NetSocket.ByteArray(replyNode.Value.Data.ToArray()));

                        break;
                    }

                    default: break;
                    }

                    mReplyList.RemoveFirst();
                }

                if (mNetState == ENetState.ES_Disconnect)
                {
                    Clear();
                }

#if USE_MULTIPACK
                mMutiPacketHelp.Send();
#endif
            }
        }
Exemplo n.º 2
0
        public void Update()
        {
            if (mListener == null)
            {
                return;
            }

            lock (mLock)
            {
                if (mNetState == ENetState.ES_Connecting)
                {
                    mConnectWaitTime += (int)(UnityEngine.Time.deltaTime * 1000.0f);
                    if (mConnectWaitTime > mConnectMaxWaitTime)
                    {
                        mNetState = ENetState.ES_Disconnect;
                        if (mSocket != null)
                        {
#if UNITY_ANDROID
                            if (Const.Region != RegionType.CHINA)
                            {
                                if (mSocket.Connected)
                                {
                                    mSocket.Shutdown(SocketShutdown.Both);
                                }
                            }
#endif
                            mSocket.Close();
                            mSocket = null;
                        }

                        mListener.OnNetDisconnect(mNetType, -1);
                    }
                }

                if (mNetState == ENetState.ES_Connected && mSocket != null && !mSocket.Connected)
                {
                    this.OnDisconnect(-1);
                }

                while (mReplyList.Count > 0)
                {
                    LinkedListNode <Reply> replyNode = mReplyList.First;
                    switch (replyNode.Value.Type)
                    {
                    case EReplyType.RT_Connected:
                        mListener.OnNetConnect(mNetType);
                        break;

                    case EReplyType.RT_Disconnect:
                        mListener.OnNetDisconnect(mNetType, replyNode.Value.e);
                        break;

                    case EReplyType.RT_DataReply:
                        mListener.OnNetDataReply(mNetType, replyNode.Value.Protocol, replyNode.Value.Data);
                        break;

                    default:
                        break;
                    }

                    replyNode.Value.Clear();
                    mReplyList.RemoveFirst();
                }

                if (mNetState == ENetState.ES_Disconnect)
                {
                    Clear();
                }

                if (mSocket != null)
                {
                    mMutiPacketHelp.Send();
                }
            }
        }