コード例 #1
0
        public void TestGoogle()
        {
            var endpoint = HostResolver.Resolve(GOOGLE, 80);

            Assert.NotNull(endpoint);
            Assert.False(string.IsNullOrEmpty(endpoint.ToString()));
        }
コード例 #2
0
        public void TestLocalhost()
        {
            var endpoint = HostResolver.Resolve(LOCAL_HOST, PORT);

            Assert.NotNull(endpoint);
            Assert.AreEqual($"{LOCAL_IPV4}:{PORT}", endpoint.ToString());
        }
コード例 #3
0
        public void TestLocalIPv6()
        {
            var endpoint = HostResolver.Resolve(LOCAL_IPV6, PORT);

            Assert.NotNull(endpoint);
            Assert.AreEqual($"[::]:{PORT}", endpoint.ToString());
        }
コード例 #4
0
        /// <summary>
        /// Add a server to the list of servers
        /// </summary>
        /// <param name="address"></param>
        /// <param name="port"></param>
        private void AddServer(string address, ushort port = NetWorker.DEFAULT_PORT, bool isLocal = true)
        {
            var hostAndPort = $"{address}:{port}";

            for (int i = 0; i < serverList.Count; ++i)
            {
                var server = serverList[i];
                if (server.Hostname == hostAndPort)
                {
                    // Already have that server listed nothing else to do
                    return;
                }
            }

            var serverListItemData = new ServerListItemData {
                ListItem = GameObject.Instantiate <ServerListEntry>(serverListEntryTemplate, servers.content),
                Hostname = hostAndPort,
                IsLocal  = isLocal
            };

            serverListItemData.ListItem.gameObject.SetActive(true);

            var endpoint = HostResolver.Resolve(address, Settings.SQPPort);

            serverListItemData.SqpQuery = sqpClient.GetQuery(endpoint);

            UpdateItem(serverListItemData);
            serverListItemData.NextUpdate = Time.time + 5.0f + UnityEngine.Random.Range(0.0f, 1.0f);

            serverList.Add(serverListItemData);
            SetListItemSelected(serverListItemData, false);

            RepositionItems();
        }
コード例 #5
0
        public void Should_MatchDomains(string domain, string path, bool isHttps, string expectedResult)
        {
            HostResolver hostResolver = new HostResolver(domainLoader.Object);
            var          httpRequest  = this.SetupHttpRequest(domain, path, isHttps);
            var          uri          = hostResolver.HostUri(httpRequest.Object);

            Assert.AreEqual(expectedResult, uri.ToString());
        }
コード例 #6
0
        private static TcpClient InitClient(string host, int port)
        {
            var endpoint = new IPEndPoint(HostResolver.Resolve(host), port);
            var client   = new TcpClient();

            client.Connect(endpoint);
            log.Debug(() => "TCP client for graphite initialized for " + host + ":" + port.ToString());
            return(client);
        }
コード例 #7
0
        public FederationClient(string serverName, SigningKey key, IConfigurationSection config)
        {
            origin = serverName;

            client = new HttpClient(new HttpClientHandler
            {
                ServerCertificateCustomValidationCallback = ServerCertificateValidationCallback
            });

            client.Timeout = TimeSpan.FromSeconds(30);

            this.key        = key;
            destinationUris = new Dictionary <string, Uri>();
            hostResolver    = new HostResolver(config.GetValue <bool>("defaultToSecurePort") ? 8448 : 8008);
            allowSelfSigned = config.GetValue <bool>("allowSelfSigned");
        }
コード例 #8
0
ファイル: ClusterServer.cs プロジェクト: steve-nzr/Hellion
        /// <summary>
        /// Connect to the Inter-Server.
        /// </summary>
        private void ConnectToISC()
        {
            Log.Info("Connecting to Inter-Server...");

            this.connector = new InterConnector(this);

            try
            {
                var resolvedIp = HostResolver.ResolveToIp(this.ClusterConfiguration.ISC.Ip);
                this.connector.Connect(resolvedIp, this.ClusterConfiguration.ISC.Port);
                this.iscThread = new Thread(this.connector.Run);
                this.iscThread.Start();
            }
            catch (Exception e)
            {
                Log.Error("Cannot connect to ISC. {0}", e.Message);
                Environment.Exit(0);
            }

            Log.Done("Connected to Inter-Server!");
        }
コード例 #9
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (TcpClientConnection client = new TcpClientConnection()) {
                client.NetworkStream = new NetworkStream();

                client.TimeOut = 60000;
                client.Open(HostResolver.GetIPAddress("127.0.0.1"), 2110);
                MessageBox.Show("Client connected");

                using (StringStream data = new StringStream("Data to be sent")) {
                    client.WriteData(data);
                    data.SetLength(0);
                    client.IsReadUntilClose = true;
                    client.ReadData(data);

                    MessageBox.Show(data.DataString);
                }

                client.Close(true);
                MessageBox.Show("Client disconnected");
            }
        }
コード例 #10
0
        private void btnPing_Click(object sender, EventArgs e)
        {
            using (var client = new IcmpConnection())
            {
                client.NetworkStream = new NetworkStream();
                client.TimeOut       = 1000;
                client.Open(HostResolver.GetIPAddress(txtHost.Text));

                txtResult.Text = "";

                for (int i = 0; i < 4; i++)
                {
                    try
                    {
                        client.SendEchoRequest();
                        var response = client.ReceiveResponse();
                        if (!(response.IcmpPacket is IcmpEchoPacket))
                        {
                            throw new Exception("Invalid ICMP reply");
                        }

                        txtResult.Text += String.Format("Reply from {0}: seq={1} received bytes={2} time={3}ms TTL={4}\r\n",
                                                        txtHost.Text,
                                                        (response.IcmpPacket as IcmpEchoPacket).SequenceNumber,
                                                        (response.IcmpPacket as IcmpEchoPacket).Data.Length,
                                                        response.RoundTripTime,
                                                        response.IpHeader.Ttl);

                        System.Threading.Thread.Sleep(1000);
                    }
                    catch (Exception ex)
                    {
                        txtResult.Text += " Error: " + ex.Message + "\r\n";
                    }
                }
            }
        }