Exemplo n.º 1
0
    private void StartNetWork()
    {
        Log.Loggers.net.Debug("StartNetWork");
        _isRunning = true;

        // 初始化连接对象;
        _tc = new TcpConnect();
        _tc.StartConnect(_host, _port);
    }
Exemplo n.º 2
0
    private void NetThreadWork()
    {
        while (!_stopNetThread)
        {
            if (!_isRunning)
            {
                if (_askStartNet)
                {
                    // 请求开始网络;
                    StartNetWork();
                    continue;
                }
                else
                {
                    // 休眠等待开启指令;
                    Thread.Sleep(10);
                }
            }
            else
            {
                _askStartNet = false;        // 已经处于开启状态, 开启请求置空

                // 网络连接并没有正真建立成功, 重新进行建立;
                if (_tc == null || _tc.CurNetState == NetState.Disconnected)
                {
                    StartNetWork();
                    continue;
                }

                // 断线, 执行断线重连;
                if (_tc.CurNetState == NetState.Droped)
                {
                    _tc.StartConnect(_host, _port);
                    continue;
                }

                // 执行消息的接收,解析,处理;
                ReceiveMessage();
            }
        }

        Log.Loggers.net.Info("Net thread stoped!");
    }