// This starts the flow of data, and it is quite an intense multi step process
        // So I will label it in sequential order
        public unsafe void Start()
        {
            _queue.DispatchAsync(() =>
            {
                if (_client != null)
                {
                    WriteLog.To.Sync.W(Tag, "Ignoring duplicate call to Start...");
                    return;
                }

                Native.c4socket_retain(_socket);
                WriteLog.To.Sync.I(Tag, "c4Socket is retained, and reachability status monitor is starting.");

                _readWriteCancellationTokenSource = new CancellationTokenSource();
                _writeQueue   = new BlockingCollection <byte[]>();
                _receivePause = new ManualResetEventSlim(true);
                _reachability.StatusChanged += ReachabilityChanged;
                _reachability.Start();
                // STEP 1: Create the TcpClient, which is responsible for negotiating
                // the socket connection between here and the server
                try {
                    // ReSharper disable once UseObjectOrCollectionInitializer
                    _client = new TcpClient(AddressFamily.InterNetworkV6);
                } catch (Exception e) {
                    DidClose(e);
                    return;
                }

                try {
                    _client.Client.DualMode = true;
                } catch (ArgumentException) {
                    WriteLog.To.Sync.I(Tag, "IPv4/IPv6 dual mode not supported on this device, falling back to IPv4");
                    _client = new TcpClient(AddressFamily.InterNetwork);
                }

                // STEP 2.5: The IProxy interface will detect a system wide proxy that is set
                // And if it is, it will return an IWebProxy object to use
                // Sending "CONNECT" request if IWebProxy object is not null
                IProxy proxy = Service.GetInstance <IProxy>();

                try {
                    if (_client != null && !_client.Connected)
                    {
                        if (proxy != null)
                        {
                            connectProxyAsync(proxy, "proxyUser", "proxyPassword");
                        }
                    }
                } catch { }

                if (proxy == null)
                {
                    OpenConnectionToRemote();
                }
            });
        }
Exemplo n.º 2
0
        private void StartReachabilityObserver()
        {
            if (_reachability != null)
            {
                return;
            }

            _reachability = Service.GetInstance <IReachability>() ?? new Reachability();
            _reachability.StatusChanged += ReachabilityChanged;
            _reachability.Start();
        }
        public unsafe WebSocketWrapper(Uri url, C4Socket *socket, [NotNull] ReplicatorOptionsDictionary options)
        {
            _socket  = socket;
            _logic   = new HTTPLogic(url);
            _options = options;
            _reachability.StatusChanged += ReachabilityChanged;
            _reachability.Url            = url;
            _reachability.Start();

            SetupAuth();
        }
Exemplo n.º 4
0
        private void StartReachabilityObserver()
        {
            if (_reachability != null)
            {
                return;
            }

            var remoteUrl = (Config.Target as URLEndpoint)?.Url;

            if (remoteUrl == null)
            {
                return;
            }

            _reachability = Service.GetInstance <IReachability>() ?? new Reachability();
            _reachability.StatusChanged += ReachabilityChanged;
            _reachability.Url            = remoteUrl;
            _reachability.Start();
        }