Esempio n. 1
0
 public NetBaseState(TcpSocket parent, NETWORKSTATE netState = NETWORKSTATE.NS_NONE, OnEnterState enter = null, OnExitState exit = null)
 {
     this.parent   = parent;
     this.netState = netState;
     onEnter       = enter;
     onExit        = exit;
 }
Esempio n. 2
0
        public NetWorkStateManager(TcpSocket socket)
        {
            tcpSocket = socket;
            AddState(new NetBaseState(tcpSocket, NETWORKSTATE.NS_NONE));
            AddState(new ConnectingNetWorkState(tcpSocket, 5000, NETWORKSTATE.NS_CONNECTING));
            AddState(new NetBaseState(tcpSocket, NETWORKSTATE.NS_CONNECTED));
            AddState(new DisConnectNetWorkState(tcpSocket, NETWORKSTATE.NS_DISCONNECTED));
            AddState(new NetBaseState(tcpSocket, NETWORKSTATE.NS_CONNECTSERVERERROR));
            AddState(new RetryNetWorkState(tcpSocket, NETWORKSTATE.NS_RETRY));

            Start(NETWORKSTATE.NS_NONE);
        }
Esempio n. 3
0
        public void Destroy()
        {
            if (tcpSocket != null)
            {
                tcpSocket.Destroy();
            }
            tcpSocket = null;

            if (msgQueue != null)
            {
                msgQueue.Clear();
            }
            msgQueue = null;

            connetCallback = null;
        }
Esempio n. 4
0
        protected override void ThreadProc(object obj)
        {
            TcpSocket me = (TcpSocket)obj;
            var       sw = Stopwatch.StartNew();

            while (!me.IsTerminateFlagSet())
            {
                me.UpdateStream();
                if (sw.ElapsedMilliseconds < 10)
                {
                    Thread.Sleep((int)(10 - sw.ElapsedMilliseconds));
                }
                sw.Reset();
            }
            me.CloseClient();
        }
 public DisConnectNetWorkState(TcpSocket parent, NETWORKSTATE state = NETWORKSTATE.NS_DISCONNECTED)
     : base(parent, state)
 {
 }
Esempio n. 6
0
 public void Init()
 {
     msgQueue  = new CSafeStreamQueue();
     tcpSocket = new TcpSocket();
 }
 public ConnectingNetWorkState(TcpSocket parent, int timeout = 5000, NETWORKSTATE state = NETWORKSTATE.NS_CONNECTING)
     : base(parent, state)
 {
     this.timeout = timeout;
 }
 public RetryNetWorkState(TcpSocket parent, NETWORKSTATE state = NETWORKSTATE.NS_RETRY)
     : base(parent, 5000, state)
 {
 }