private async Task Connect(IYield yield, PeerConnectionInformation connectionInformation)
        {
            isConnecting = true;

            try
            {
                outboundServerPeer = await serverConnectorProvider.GetServerConnector().Connect(yield, connectionInformation);
            }
            catch (CouldNotConnectToPeerException exception)
            {
                if (exception.Message != string.Empty && !exception.Message.Equals(exceptionMessage))
                {
                    LogUtils.Log($"Failed connect to {connectionInformation.Ip}:{connectionInformation.Port}. Details: {exception.Message}");
                    exceptionMessage = exception.Message;
                }
            }
            finally
            {
                if (IsConnected())
                {
                    SetNetworkTrafficState(NetworkTrafficState.Flowing);

                    connectContinuously?.Dispose();
                    onConnected?.Invoke(outboundServerPeer);
                }
            }

            isConnecting = false;
        }
Пример #2
0
        private void OnConnected(IOutboundServerPeer outboundServerPeer)
        {
            OutboundServerPeer = outboundServerPeer;

            SubscribeToDisconnectionNotifier();

            OnConnectionEstablished();
        }
 public void Disconnect()
 {
     if (IsConnected())
     {
         outboundServerPeer.Disconnect();
         outboundServerPeer = null;
     }
 }
        private IEnumerator <IYieldInstruction> ConnectContinuously(PeerConnectionInformation connectionInformation)
        {
            const int DELAY_TIME = 10;

            outboundServerPeer = null;

            while (true)
            {
                yield return(new WaitForSeconds(DELAY_TIME));

                if (!isConnecting && !IsConnected())
                {
                    coroutinesManager.StartTask((yield) => Connect(yield, connectionInformation));
                }
            }
        }
 public OutboundServerPeerLogicBase(IOutboundServerPeer outboundServerPeer)
 {
     this.outboundServerPeer = outboundServerPeer;
 }
Пример #6
0
 public CommonServerAuthenticationPeerLogic(IOutboundServerPeer outboundServerPeer, string secretKey, Action onAuthenticated)
     : base(outboundServerPeer)
 {
     this.secretKey       = secretKey.AssertNotNull(MessageBuilder.Trace("Secret key not found."));
     this.onAuthenticated = onAuthenticated;
 }
Пример #7
0
        public static IOutboundServerPeerLogic CreateOutboundServerPeerLogic <TOperationCode, TEventCode>(this IOutboundServerPeer outboundServerPeer)
            where TOperationCode : IComparable, IFormattable, IConvertible
            where TEventCode : IComparable, IFormattable, IConvertible
        {
            var outboundServerPeerLogicBase = new OutboundServerPeerLogicBase <TOperationCode, TEventCode>(outboundServerPeer);

            outboundServerPeerLogicBase.Initialize();
            return(outboundServerPeerLogicBase);
        }
Пример #8
0
        public static IOutboundServerPeerLogic CreateCommonServerAuthenticationPeerLogic(this IOutboundServerPeer outboundServerPeer,
                                                                                         string secretKey, Action onAuthenticated)
        {
            var commonServerAuthenticationPeerLogic = new CommonServerAuthenticationPeerLogic(outboundServerPeer,
                                                                                              secretKey, onAuthenticated);

            commonServerAuthenticationPeerLogic.Initialize();
            return(commonServerAuthenticationPeerLogic);
        }