Exemplo n.º 1
0
    private void OnNetWorkStateChange(NetWorkState state)
    {
        Debug.Log("GameServerNetState------------------>" + state.ToString());
        switch (state)
        {
        case NetWorkState.CLOSED:
            break;

        case NetWorkState.CONNECTING:
            break;

        case NetWorkState.CONNECTED:
            break;

        case NetWorkState.TIMEOUT:
            ChangeConnectStatus(ConnectStatus.TIMEOUT);
            break;

        case NetWorkState.DISCONNECTED:
            ChangeConnectStatus(ConnectStatus.DISCONNECT);
            break;

        case NetWorkState.ERROR:
            ChangeConnectStatus(ConnectStatus.ERROR);
            break;

        default:
            break;
        }
    }
Exemplo n.º 2
0
    private void OnGateServerNetWorkStateChange(NetWorkState state)
    {
        Debug.Log("GateServerNetState------------------>" + state.ToString());
        switch (state)
        {
        case NetWorkState.CLOSED:
            break;

        case NetWorkState.CONNECTING:

            break;

        case NetWorkState.CONNECTED:
            break;

        case NetWorkState.DISCONNECTED:
            if (!activeCloseConnect)
            {
                ChangeConnectStatus(ConnectStatus.ERROR);
            }
            break;

        case NetWorkState.TIMEOUT:
            ChangeConnectStatus(ConnectStatus.TIMEOUT);
            break;

        case NetWorkState.ERROR:
            ChangeConnectStatus(ConnectStatus.ERROR);
            break;
        }
    }
Exemplo n.º 3
0
        public void Connect()
        {
            if (_handler == null || _protocol == null || _mb == null)
            {
                netWorkState = NetWorkState.CLOSED;
                throw new Exception("handler null");
            }

            if (netWorkState != NetWorkState.CLOSED)
            {
                throw new Exception("state err" + netWorkState.ToString());
            }

            _startConnectTime = Time.realtimeSinceStartup;
            netWorkState      = NetWorkState.CONNECTING;
            _mb.StartCoroutine(_AutoUpdate());

            IPAddress ipAddress = null;

            try
            {
                // this implement quickly
                IPAddress[] ips;
                ips = Dns.GetHostAddresses(_host);
                foreach (IPAddress ipa in ips)
                {
                    if (ipa.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        ipAddress = ipa;
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                OnDisconnect(1, e.ToString());
                return;
            }

            if (ipAddress == null)
            {
                OnDisconnect(2, "can not parse host : " + _host);
                return;
            }

            this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint ie = new IPEndPoint(ipAddress, _port);

            socket.BeginConnect(ie, new AsyncCallback(Callback_ConnectOk), this.socket);
            _resvMsgQueue.Clear();
            _sendQueue.Clear();
            _tryDisconnect = 0;
        }
Exemplo n.º 4
0
 public void NetWorkStateChangedEvent(NetWorkState state)
 {
     Debug.Log("NetWorkStateChangedEvent:" + state.ToString());
     Loom.QueueOnMainThread(() => {
         connectState = state;
         if (NetWorkState.CONNECTED == state)
         {
             TipManager.instance.hideReconnectPanel();
         }
         else if (NetWorkState.CONNECTING == state)
         {
         }
         else                //连接错误
                             //TipManager.instance.showReconnectPanel(1);
                             //Debug.Log("isShowReConnectPanel:" + isShowReConnectPanel.ToString());
                             //if (isShowReConnectPanel) {
         {
             TipManager.instance.showReconnectPanel(1);
             //}
             //isShowReConnectPanel = true;
         }
     });
 }
Exemplo n.º 5
0
        public void Open()
        {
            if (_handler == null || _mb == null)
            {
                netWorkState = NetWorkState.CLOSED;
                throw new Exception("handler null");
            }

            if (netWorkState != NetWorkState.CLOSED)
            {
                throw new Exception("state err" + netWorkState.ToString());
            }

            netWorkState      = NetWorkState.CONNECTING;
            _startConnectTime = Time.realtimeSinceStartup;

            _mb.StartCoroutine(_AutoUpdate());
            this._webSocket = new WebSocket(_url);
            RegisterEvt(true);

            _resvMsgQueue.Clear();
            _sendQueue.Clear();
            this._webSocket.ConnectAsync();
        }
Exemplo n.º 6
0
 //工作线程回调
 private void OnPemeloNetworkStateChange(NetWorkState st)
 {
     JW.Common.Log.LogD("<color=green>OnPemeloNetworkStateChange:</color>" + st.ToString());
     _curNetworkState = st;
 }
Exemplo n.º 7
0
 private void OnNetWorkStateChange(NetWorkState state)
 {
     Debug.Log(state.ToString());
 }