public void connect()
        {
#if LUZEXI
            connect(null, null);
#else
            protocol.start(null, null);
#endif
        }
        private void AsyncCallback(IAsyncResult result)
        {
            // socket 连接失败
            string error = this._asyncDel.EndInvoke(result).Trim();

            if (string.IsNullOrEmpty(error) == false)
            {
                this._isConnected = false;
                if (this.OnException != null)
                {
                    this.OnException(error);
                }

                return;
            }

            // 启动协议,开始握手
            StartParamType type = (StartParamType)result.AsyncState;

            try
            {
                switch (type)
                {
                case StartParamType.NONE:
                    protocol.start(null, null);
                    break;

                case StartParamType.JSON:
                    protocol.start(this._user, null);
                    break;

                case StartParamType.HAND_SHAKE_CALLBACK:
                    protocol.start(null, this._handshakeCallback);
                    break;

                case StartParamType.ALL:
                    protocol.start(this._user, this._handshakeCallback);
                    break;
                }

                this._isConnected = true;
                if (this.OnConnect != null)
                {
                    this.OnConnect();
                }
            }
            catch (Exception e)
            {
                this._isConnected = false;
                if (this.OnException != null)
                {
                    this.OnException(e.Message);
                }
            }
        }
示例#3
0
 private bool tryHandshake(JsonObject user, Action <JsonObject> handshakeCallback)
 {
     try{
         protocol.start(user, handshakeCallback);
         return(true);
     }
     catch (Exception e) {
         Debug.Log(e.ToString());
         return(false);
     }
 }
示例#4
0
 public bool connect(JsonObject user, Action <JsonObject> handshakeCallback)
 {
     try
     {
         protocol.start(user, handshakeCallback);
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
         return(false);
     }
 }
        public void connect(JsonObject user, Action <bool, JsonObject> handshakeCallback)
        {
            if (!inited)
            {
                handshakeCallback(false, null);
                return;
            }

            try
            {
                protocol.start(user, (obj) => { handshakeCallback(true, obj); });
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                handshakeCallback(false, null);
            }
        }
示例#6
0
        public bool connect(JsonObject user, Action <JsonObject> handshakeCallback)
        {
            ManualResetEvent timeoutEvent = new ManualResetEvent(false);

            try
            {
                protocol.start(user, (JsonObject json) =>
                {
                    timeoutEvent.Set();
                    try
                    {
                        if (handshakeCallback != null)
                        {
                            handshakeCallback(json);
                        }
                    }
                    catch (SocketException e)
                    {
                        if (netWorkState != NetWorkState.DISCONNECTED &&
                            netWorkState != NetWorkState.TIMEOUT &&
                            netWorkState != NetWorkState.ERROR &&
                            netWorkState != NetWorkState.KICK)
                        {
                            error();
                        }
                    }
                });

                timeoutEvent.WaitOne(timeoutMSec, false);
                if (!protocol.isWaking())
                {
                    timeout();
                }
                return(true);
            }
            catch (Exception e)
            {
                Trace.TraceInformation(e.ToString());
            }
            timeoutEvent.Close();
            timeoutEvent = null;
            error();
            return(false);
        }
示例#7
0
 public bool HandShake(JsonData user, Action <JsonData> handshakeCallback)
 {
     try
     {
         this.handShakeCallBack = handshakeCallback;
         protocol.start(user, delegate(JsonData data)
         {
             lock (guard)
             {
                 this.handShakeCallBackData    = new JsonData();
                 this.handShakeCallBackData    = data;
                 this.handShakeCallBackCanCall = true;
             }
         });
         return(true);
     }
     catch (Exception e)
     {
         Debug.Log(e);
         return(false);
     }
 }
示例#8
0
 public void Connect()
 {
     protocol.start(null, null);
 }