Exemplo n.º 1
0
 void outofNetConnect()
 {
     if (isStopping)
     {
         return;
     }
     if (reConnectTimes < MaxReConnectTimes)
     {
         reConnectTimes++;
         if (timer != null)
         {
             timer.Dispose();
         }
         timer = TimerEx.schedule(connect, null, 5000);
     }
     else
     {
         if (timer != null)
         {
             timer.Dispose();
         }
         timer = null;
         outofLine(socket, null);
     }
 }
Exemplo n.º 2
0
 public void outofNetConnect(int code, string msg)
 {
     if (isStopping)
     {
         return;
     }
     if (reConnectTimes < MaxReConnectTimes)
     {
         reConnectTimes++;
         Debug.LogWarning("reconnect times=" + reConnectTimes);
         if (timer != null)
         {
             timer.Dispose();
         }
         timer = TimerEx.schedule(connect, null, 5000);
     }
     else
     {
         if (timer != null)
         {
             timer.Dispose();
         }
         timer = null;
         outofLine(socket, null);
     }
 }
Exemplo n.º 3
0
        public void connectAsync(NetCallback onConnectStateChgCallback)
        {
            try
            {
                isActive = false;
                this.onConnectStateChgCallback = onConnectStateChgCallback;
                if (ipe == null)
                {
                    onConnectStateChg(false, Errors.IPEndPointIsNull);
                    return;
                }

                mSocket.BeginConnect(ipe, (AsyncCallback)connectCallback, this);
                if (connectTimeout != null)
                {
                    connectTimeout.Dispose();
                    connectTimeout = null;
                }
                connectTimeout = TimerEx.schedule((TimerCallback)connectTimeOut, null, timeoutMSec);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
        }
Exemplo n.º 4
0
		public void connectAsync (NetCallback callback, NetCallback offLineCallback)
		{
			if (ipe == null) {
				callback (this, false);
				return;
			}
			this.offLineCallback = offLineCallback;
			IsConnectionSuccessful = false;
			connectCallbackFunc = callback;

			mSocket.BeginConnect (ipe, (AsyncCallback)connectCallback, this);
            if(connectTimeout != null) {
                connectTimeout.Dispose();
                connectTimeout = null;
            }
            connectTimeout = TimerEx.schedule((TimerCallback)connectTimeOut, null, timeoutMSec);
        }
Exemplo n.º 5
0
		public void SendAsync (byte[] data)
		{
			try {
				if (data == null)
					return;
				// isOpen始发送Number据到远程设备.
				if (this.timeoutCheckTimer == null) {
					this.timeoutCheckTimer = TimerEx.schedule ((TimerCallback)sendTimeOut, null, timeoutMSec);
				}
				mSocket.BeginSend (data, 0, data.Length, 0,
					(AsyncCallback)SendCallback, this);
			} catch (System.Exception e) {
				Debug.LogError ("socket:" + e);
				if (offLineCallback != null) {
					offLineCallback (this, null);
				}
				close ();
			}
		}
Exemplo n.º 6
0
        public void SendAsync(byte[] data)
        {
            try
            {
                if (data == null)
                {
                    return;
                }
                // isOpen始发送Number据到远程设备.
                if (this.timeoutCheckTimer == null)
                {
                    this.timeoutCheckTimer = TimerEx.schedule((TimerCallback)sendTimeOut, null, timeoutMSec);
                }

                mSocket.BeginSend(data, 0, data.Length, 0,
                                  (AsyncCallback)SendCallback, this);
            }
            catch (Exception e)
            {
                Debug.LogError("socket:" + e);
                onConnectStateChg(false, Errors.sendAsynException);
            }
        }