Ejemplo n.º 1
0
        public bool ClientInit(byte[] verificationCode, NetworkfConnection applyTo)
        {
            Log("waiting server hello...");
            lock (mtx) {
                while (!_hasReceivedServerHello)
                {
                    Monitor.Wait(mtx);
                }
            }
            Log("server hello received");
            var verifyMsg = new CltVerifyMessage();

            verifyMsg.verificationCode = verificationCode;
            _service.SendMessage(verifyMsg);
            Log("waiting verification result...");
            lock (mtx) {
                while (!_hasReceivedServerResult)
                {
                    Monitor.Wait(mtx);
                }
            }
            Log("verification result received");
            if (_verificationResult)
            {
                ReleaseService();
                applyTo.ApplyService(_service);
                applyTo.AddMessageReceiver(ServerReadyMessage.MESSAGE_TYPE, this);
                _service.SendMessage(new CltReadyMessage());
                Log("client ready has sent");
                Log("waiting server ready...");
                while (!_hasReceivedServerReady)
                {
                    Thread.Sleep(100);
                    applyTo.UpdateReceiver();
                }
                Log("server ready received");
                applyTo.RemoveMessageReceiver(ServerReadyMessage.MESSAGE_TYPE, this);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public void ServerApplyConnection(NetworkfConnection applyTo)
        {
            var serMsg = new SerVerifyResultMessage();

            serMsg.result = applyTo != null;
            _service.SendMessage(serMsg);
            Log("verification result has sent");
            if (applyTo != null)
            {
                int tryCount = 0;
                Log("waiting client ready...");
                lock (mtx) {
                    while (!_hasReceivedClientReady && tryCount < _retryCount)
                    {
                        Monitor.Wait(mtx, _retryDelay);
                        ++tryCount;
                    }
                }
                if (!_hasReceivedClientReady)
                {
                    Log("broken client");
                    ReleaseService();
                    _service.TeardownService();
                    return;
                }
                Log("client ready received");
                ReleaseService();
                applyTo.ApplyService(_service);
                applyTo.SendMessage(new ServerReadyMessage());
            }
            else
            {
                ReleaseService();
                _service.TeardownService();
            }
        }