Example #1
0
        private void InitializeNetworkProvider()
        {
            networkRelays = new List <NetworkRelay <HeartRateMessage> >();
            TcpRelayClient <HeartRateMessage> client = new TcpRelayClient <HeartRateMessage>();

            client.Timeout = 10000;
            client.Version = networkVersion;
            networkRelays.Add(client);

            TcpRelayServer <HeartRateMessage> server = new TcpRelayServer <HeartRateMessage>();

            server.MaxConnections = 4;
            server.Timeout        = 10000;
            server.Version        = networkVersion;
            networkRelays.Add(server);

            NetworkMode           = configuration.Network.Mode;
            networkRelay.Port     = configuration.Network.Port;
            networkRelay.Nickname = configuration.Network.Nickname;

            client.ServerAddress = configuration.Network.Address;

            networkSampler = new NetworkSampler(this);
            networkSampler.PacketSampled += networkSampler_PacketSampled;
        }
        private void ConnectionManager_InternetConnectivityStatusChanged(object sender, EventArgs e)
        {
            IPEndPoint externalEP = _connectionManager.ExternalEndPoint;

            if (externalEP == null)
            {
                //no incoming connection possible; start tcp relay client
                if (_tcpRelayClient == null)
                {
                    _tcpRelayClient = new TcpRelayClient(_connectionManager);
                }
            }
            else
            {
                //can receive incoming connection; no need for running tcp relay client
                if (_tcpRelayClient != null)
                {
                    _tcpRelayClient.Dispose();
                    _tcpRelayClient = null;
                }
            }
        }
        private void profile_ProxyUpdated(object sender, EventArgs e)
        {
            //stop all existing relay connections if any; internet connectivity check will auto start tcp relay client if needed via new proxy route
            if (_tcpRelayClient != null)
            {
                _tcpRelayClient.Dispose();
                _tcpRelayClient = null;
            }

            _connectionManager.ClientProfileProxyUpdated();

            lock (_chats)
            {
                foreach (KeyValuePair <BinaryID, BitChat> chat in _chats)
                {
                    try
                    {
                        chat.Value.ClientProfileProxyUpdated();
                    }
                    catch
                    { }
                }
            }
        }