• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Net.DnsEndPoint类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Net.DnsEndPoint的典型用法代码示例。如果您正苦于以下问题:C# DnsEndPoint类的具体用法?C# DnsEndPoint怎么用?C# DnsEndPoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DnsEndPoint类属于System.Net命名空间,在下文中一共展示了DnsEndPoint类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: IsPortReachable

        public async Task<bool> IsPortReachable(string host, int port = 80, int msTimeout = 5000)
        {
            if (string.IsNullOrEmpty(host))
                throw new ArgumentNullException("host");

            return await Task.Run(() =>
                {
                    var clientDone = new ManualResetEvent(false);
                    var reachable = false;
                    var hostEntry = new DnsEndPoint(host, port);
                    using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
                    {
                        var socketEventArg = new SocketAsyncEventArgs { RemoteEndPoint = hostEntry };
                        socketEventArg.Completed += (s, e) =>
                        {
                            reachable = e.SocketError == SocketError.Success;

                            clientDone.Set();
                        };

                        clientDone.Reset();

                        socket.ConnectAsync(socketEventArg);

                        clientDone.WaitOne(msTimeout);

                        return reachable;
                    }
                });
        }
开发者ID:vinzandtonz,项目名称:Cheesebaron.MvxPlugins,代码行数:30,代码来源:Connectivity.cs


示例2: Connect

        public void Connect(string host, int port)
        {
            DnsEndPoint endPoint = new DnsEndPoint(host, port);
            SocketAsyncEventArgs asEventArg = new SocketAsyncEventArgs();
            asEventArg.RemoteEndPoint = endPoint;
            _myEvent.Reset();
            asEventArg.Completed += (object sender, SocketAsyncEventArgs arg) =>
            {
                if (arg.SocketError == SocketError.Success)
                {
                    Debug.WriteLine("Connect with Server");
                    Debug.WriteLine("Start to send SocketFlag");
                    m_host = host;
                    m_port = port;
                    byte[] socketFlag = new byte[1];
                    socketFlag[0] = (byte)m_protocolFlag;
                    SendSocketFlag(socketFlag);
                    Debug.WriteLine("SocketFlag has sent");

                }
                else
                {
                    Debug.WriteLine("Did not connect with Server... \nThe Reson is {0}",arg.SocketError.ToString());
                }
                _myEvent.Set();
            };
            m_tcpClient.ConnectAsync(asEventArg);
            _myEvent.WaitOne(Timeout);
        }
开发者ID:sduxzh,项目名称:ShareULocation,代码行数:29,代码来源:SyncSocketInvokeElement.cs


示例3: Setup

        public void Setup()
        {
            _capturedEvents = new EventCapturer()
                .Capture<CommandStartedEvent>()
                .Capture<CommandSucceededEvent>()
                .Capture<CommandFailedEvent>();

            _streamFactory = Substitute.For<IStreamFactory>();

            _endPoint = new DnsEndPoint("localhost", 27017);
            var serverId = new ServerId(new ClusterId(), _endPoint);

            _connectionInitializer = Substitute.For<IConnectionInitializer>();
            _connectionInitializer.InitializeConnectionAsync(null, CancellationToken.None)
                .ReturnsForAnyArgs(Task.FromResult(new ConnectionDescription(
                    new ConnectionId(serverId),
                    new IsMasterResult(new BsonDocument()),
                    new BuildInfoResult(new BsonDocument("version", "2.6.3")))));

            _subject = new BinaryConnection(
                serverId: serverId,
                endPoint: _endPoint,
                settings: new ConnectionSettings(),
                streamFactory: _streamFactory,
                connectionInitializer: _connectionInitializer,
                eventSubscriber: _capturedEvents);

            _stream = new BlockingMemoryStream();
            _streamFactory.CreateStreamAsync(null, CancellationToken.None)
                .ReturnsForAnyArgs(Task.FromResult<Stream>(_stream));
            _subject.OpenAsync(CancellationToken.None).Wait();
            _capturedEvents.Clear();

            _operationIdDisposer = EventContext.BeginOperation();
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:35,代码来源:BinaryConnection_CommandEventTests.cs


示例4: BinaryConnection_CommandEventTests

        public BinaryConnection_CommandEventTests()
        {
            _capturedEvents = new EventCapturer()
                .Capture<CommandStartedEvent>()
                .Capture<CommandSucceededEvent>()
                .Capture<CommandFailedEvent>();

            _mockStreamFactory = new Mock<IStreamFactory>();

            _endPoint = new DnsEndPoint("localhost", 27017);
            var serverId = new ServerId(new ClusterId(), _endPoint);

            _mockConnectionInitializer = new Mock<IConnectionInitializer>();
            _mockConnectionInitializer.Setup(i => i.InitializeConnectionAsync(It.IsAny<IConnection>(), CancellationToken.None))
                .Returns(() => Task.FromResult(new ConnectionDescription(
                    new ConnectionId(serverId),
                    new IsMasterResult(new BsonDocument()),
                    new BuildInfoResult(new BsonDocument("version", "2.6.3")))));

            _subject = new BinaryConnection(
                serverId: serverId,
                endPoint: _endPoint,
                settings: new ConnectionSettings(),
                streamFactory: _mockStreamFactory.Object,
                connectionInitializer: _mockConnectionInitializer.Object,
                eventSubscriber: _capturedEvents);

            _stream = new BlockingMemoryStream();
            _mockStreamFactory.Setup(f => f.CreateStreamAsync(_endPoint, CancellationToken.None))
                .Returns(Task.FromResult<Stream>(_stream));
            _subject.OpenAsync(CancellationToken.None).Wait();
            _capturedEvents.Clear();

            _operationIdDisposer = EventContext.BeginOperation();
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:35,代码来源:BinaryConnection_CommandEventTests.cs


示例5: button1_Click

 private void button1_Click(object sender, RoutedEventArgs e)
 {
     if (loginTB.Text == "")
     {
         MessageBox.Show("Задайте имя пользователя");
         return;
     }
     if (addressTB.Text == "")
     {
         MessageBox.Show("Задайте адрес сервера");
         return;
     }
     DnsEndPoint endPoint;
     try
     {
         endPoint = new DnsEndPoint(addressTB.Text, int.Parse(portTB.Text));
     }
     catch
     {
         MessageBox.Show("Неверный адрес сервера");
         return;
     }
     GameProcess.Inctance.UserName = loginTB.Text;
     Client.Current.ConnectAsync(endPoint.Host, endPoint.Port);
     this.Close();
 }
开发者ID:kalashnikovisme,项目名称:Seti,代码行数:26,代码来源:ConnectForm.xaml.cs


示例6: TryConvertTo

        public bool TryConvertTo(Type type, string stringValue, out object converted)
        {
            if (type != typeof(DnsEndPoint))
            {
                converted = null;
                return false;
            }

            int idx = stringValue.IndexOf(':');
            if (idx == -1)
            {
                converted = null;
                return false;
            }

            string host = stringValue.Substring(0, idx);

            int port;
            if (!int.TryParse(stringValue.Substring(idx + 1), out port))
            {
                converted = null;
                return false;
            }

            try
            {
                converted = new DnsEndPoint(host, port);
                return true;
            }
            catch (ArgumentException)
            {
                converted = null;
                return false;
            }
        }
开发者ID:innix,项目名称:ini-dot-net,代码行数:35,代码来源:DnsEndPointConverter.cs


示例7: BinaryConnectionTests

        public BinaryConnectionTests()
        {
            _capturedEvents = new EventCapturer();
            _mockStreamFactory = new Mock<IStreamFactory>();

            _endPoint = new DnsEndPoint("localhost", 27017);
            var serverId = new ServerId(new ClusterId(), _endPoint);

            _mockConnectionInitializer = new Mock<IConnectionInitializer>();
            _mockConnectionInitializer.Setup(i => i.InitializeConnection(It.IsAny<IConnection>(), CancellationToken.None))
                .Returns(() => new ConnectionDescription(
                    new ConnectionId(serverId),
                    new IsMasterResult(new BsonDocument()),
                    new BuildInfoResult(new BsonDocument("version", "2.6.3"))));
            _mockConnectionInitializer.Setup(i => i.InitializeConnectionAsync(It.IsAny<IConnection>(), CancellationToken.None))
                .Returns(() => Task.FromResult(new ConnectionDescription(
                    new ConnectionId(serverId),
                    new IsMasterResult(new BsonDocument()),
                    new BuildInfoResult(new BsonDocument("version", "2.6.3")))));

            _subject = new BinaryConnection(
                serverId: serverId,
                endPoint: _endPoint,
                settings: new ConnectionSettings(),
                streamFactory: _mockStreamFactory.Object,
                connectionInitializer: _mockConnectionInitializer.Object,
                eventSubscriber: _capturedEvents);
        }
开发者ID:XiaoPingJiang,项目名称:mongo-csharp-driver,代码行数:28,代码来源:BinaryConnectionTests.cs


示例8: ConnectTo

        public void ConnectTo(DnsEndPoint hostEntry)
        {
            _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            SocketError _lastError = SocketError.NotConnected;
            SocketAsyncEventArgs socketEventArgs = new SocketAsyncEventArgs();

            socketEventArgs.RemoteEndPoint = hostEntry;
            socketEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(delegate(object s, SocketAsyncEventArgs e)
            {
                _lastError = e.SocketError;
                _End();
                // Install read and write handler
                _socketReadEventArgs = new SocketAsyncEventArgs();
                _socketReadEventArgs.RemoteEndPoint = _socket.RemoteEndPoint;
                _socketReadEventArgs.SetBuffer(new byte[MAX_BUFFER_SIZE], 0, MAX_BUFFER_SIZE);
                _socketReadEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(_AsyncCallComplete);

                _socketWriteEventArgs = new SocketAsyncEventArgs();
                _socketWriteEventArgs.RemoteEndPoint = _socket.RemoteEndPoint;
                _socketWriteEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(_AsyncCallComplete);
            });

            // async connect
            _Reset();
            _socket.ConnectAsync(socketEventArgs);
            _BlockUI();

            if (_lastError != SocketError.Success)
            {
                // connection failed
                throw new Exception(String.Format(LocalizedStrings.Get("Net_StreamSocket_ConnectFailed"), hostEntry, _lastError.ToString()));
            }            
        }
开发者ID:ErikPel,项目名称:windows-phone,代码行数:33,代码来源:StreamSocket.cs


示例9: Connect

        public bool Connect()
        {
            if (!_isConnected)
            {
                if (_consoleIP == "" || _consoleIP == null)
                    return false;

                _isConnected = false;
                DnsEndPoint hostEntry = new DnsEndPoint(_consoleIP, _consolePort);
                _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
                socketEventArg.RemoteEndPoint = hostEntry;
                socketEventArg.Completed += (o, args) =>
                    {
                        _pausingThread.Set();
                    };
                _pausingThread.Reset();
                _socket.ConnectAsync(socketEventArg);
                _pausingThread.WaitOne(CONNECTION_TIMEOUT_MILLISECONDS);

                // Send test command
                _isConnected = IsConnected();

                return _isConnected;
            }
            else
                return true;
        }
开发者ID:0xdeafcafe,项目名称:Neighbourhood360,代码行数:29,代码来源:XBDM.cs


示例10: Setup

        public void Setup()
        {
            _capturedEvents = new EventCapturer();
            _streamFactory = Substitute.For<IStreamFactory>();

            _endPoint = new DnsEndPoint("localhost", 27017);
            var serverId = new ServerId(new ClusterId(), _endPoint);

            _connectionInitializer = Substitute.For<IConnectionInitializer>();
            _connectionInitializer.InitializeConnection(null, CancellationToken.None)
                .ReturnsForAnyArgs(new ConnectionDescription(
                    new ConnectionId(serverId),
                    new IsMasterResult(new BsonDocument()),
                    new BuildInfoResult(new BsonDocument("version", "2.6.3"))));
            _connectionInitializer.InitializeConnectionAsync(null, CancellationToken.None)
                .ReturnsForAnyArgs(Task.FromResult(new ConnectionDescription(
                    new ConnectionId(serverId),
                    new IsMasterResult(new BsonDocument()),
                    new BuildInfoResult(new BsonDocument("version", "2.6.3")))));

            _subject = new BinaryConnection(
                serverId: serverId,
                endPoint: _endPoint,
                settings: new ConnectionSettings(),
                streamFactory: _streamFactory,
                connectionInitializer: _connectionInitializer,
                eventSubscriber: _capturedEvents);
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:28,代码来源:BinaryConnectionTests.cs


示例11: ConnectAsync

        public async Task<ConnectResult> ConnectAsync(string hostName, int port, string user, string oauth)
        {
            if (m_connected)
                throw new InvalidOperationException("Already connected to twitch chat.");

            m_endpoint = new DnsEndPoint(hostName, port);
            m_user = user;
            m_oauth = oauth;

            while (true)
            {
                try
                {
                    while (!NativeMethods.IsConnectedToInternet())
                        Thread.Sleep(5000);

                    m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    return await BeginSocketConnect();
                }
                catch (SocketException)
                {
                    Log.Irc.ConnectionFailed();
                    Thread.Sleep(5000);
                }
            }
        }
开发者ID:carriercomm,项目名称:TwitchLib,代码行数:26,代码来源:Irc.cs


示例12: Connect

        public string Connect(string hostName, int portNumber)
        {
            string result = string.Empty;
            DnsEndPoint hostEntry = new DnsEndPoint (hostName, portNumber);
            _socket = new Socket (
                AddressFamily.InterNetwork,
                SocketType.Stream,
                ProtocolType.Tcp
            );
            SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs ();
            socketEventArg.RemoteEndPoint = hostEntry;

            socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs> (delegate(object s, SocketAsyncEventArgs e)
                {
                    result = e.SocketError.ToString ();
                    _clientDone.Set ();
                }
            );

            _clientDone.Reset ();
            _socket.ConnectAsync (socketEventArg);
            _clientDone.WaitOne (TIMEOUT_MILLISECONDS);

            return result;
        }
开发者ID:meatballhat,项目名称:box-o-sand,代码行数:25,代码来源:SocketClient.cs


示例13: SendData

        /// <summary> 
        /// Send data to the server 
        /// </summary> 
        /// <param name="data">The data to send</param> 
        /// <remarks> This is an asynchronous call, with the result being passed to the callee 
        /// through the ResponseReceived event</remarks> 
        public void SendData(string data)
        {
            if (String.IsNullOrWhiteSpace(data))
            {
                throw new ArgumentNullException("data");
            }

            dataIn = data;

            SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();

            DnsEndPoint hostEntry = new DnsEndPoint(_serverName, _port);

            // Create a socket and connect to the server

            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(SocketEventArg_Completed);
            socketEventArg.RemoteEndPoint = hostEntry;

            socketEventArg.UserToken = sock;

            try
            {
                sock.ConnectAsync(socketEventArg);
            }
            catch (SocketException ex)
            {
                throw new SocketException((int)ex.ErrorCode);
            }
        }
开发者ID:kritingokharu,项目名称:ClassFinderFinal,代码行数:36,代码来源:AsynchronousSocketClient.cs


示例14: ResolveHostNameAsync

        public static Task<NameResolutionResult> ResolveHostNameAsync(DnsEndPoint dnsEndPoint)
        {
            var taskCompletionSource = new TaskCompletionSource<NameResolutionResult>();

            DeviceNetworkInformation.ResolveHostNameAsync(dnsEndPoint,
                r =>
                {
                    var tcs = (TaskCompletionSource<NameResolutionResult>)r.AsyncState;

                    switch (r.NetworkErrorCode)
                    {
                        case NetworkError.NameResolutionOperationAborted:
                            tcs.TrySetCanceled();
                            break;
                        case NetworkError.Success:
                            tcs.TrySetResult(r);
                            break;
                        default:
                            tcs.TrySetException(new NetworkException(r.NetworkErrorCode));
                            break;
                    }
                }, taskCompletionSource);

            return taskCompletionSource.Task;
        }
开发者ID:henricj,项目名称:SM.Mono.Net,代码行数:25,代码来源:DnsResolver.cs


示例15: SocketClient

 /// <summary>
 /// Initializes a new instance of the <see cref="SocketClient"/> class.
 /// </summary>
 /// <param name="host">The host.</param>
 /// <param name="port">The port.</param>
 internal SocketClient(string host, int port)
 {
     endPoint = new DnsEndPoint(host, port);
     socket = new Socket(AddressFamily.InterNetwork
                 /* hostEndPoint.AddressFamily */,
                 SocketType.Stream, ProtocolType.Tcp);
 }
开发者ID:chuckconway,项目名称:chucksoft-gallery,代码行数:12,代码来源:SocketClient.cs


示例16: ForConnectionPool_should_create_expected_message

        public void ForConnectionPool_should_create_expected_message()
        {
            var endPoint = new DnsEndPoint("localhost", 27017);
            var subject = MongoWaitQueueFullException.ForConnectionPool(endPoint);

            subject.Message.Should().Be("The wait queue for acquiring a connection to server localhost:27017 is full.");
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:7,代码来源:MongoWaitQueueFullExceptionTests.cs


示例17: Connect

        /// <summary>
        /// Connect to the server
        /// </summary>
        /// <param name="ipAddress">IP address of the server</param>
        /// <param name="port">port to connect to</param>
        /// <returns></returns>
        public string Connect(string ipAddress, int port)
        {
            string result = string.Empty;
            bool finished = false;

            DnsEndPoint host = new DnsEndPoint(ipAddress, port);

            this.sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            SocketAsyncEventArgs socketEventArgs = new SocketAsyncEventArgs();
            socketEventArgs.RemoteEndPoint = host;

            socketEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(
                delegate (object s, SocketAsyncEventArgs e)
                {
                    result = e.SocketError.ToString();

                    this.clientDone.Set();
                    finished = true;
                });
            this.clientDone.Reset();

            this.sock.ConnectAsync(socketEventArgs);

            this.clientDone.WaitOne(TCPIPconnectorClient.timeout);

            if (!finished)
            {
                result = "!error";
            }

            return result;
        }
开发者ID:WilliamPring,项目名称:SET,代码行数:39,代码来源:TCPIPconnectorClient.cs


示例18: RequestTime

        /// <summary>
        /// Begins the network communication required to retrieve the time from the NTP server
        /// </summary>
        public void RequestTime()
        {
            byte[] buffer = new byte[48];
            buffer[0] = 0x1B;
            for (var i = 1; i < buffer.Length; ++i)
                buffer[i] = 0;
            DnsEndPoint _endPoint = new DnsEndPoint(_serverName, 123);

            _socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            SocketAsyncEventArgs sArgsConnect = new SocketAsyncEventArgs() { RemoteEndPoint = _endPoint };
            sArgsConnect.Completed += (o, e) =>
                                          {
                                              if (e.SocketError == SocketError.Success)
                                              {
                                                  SocketAsyncEventArgs sArgs = new SocketAsyncEventArgs()
                                                                                   {RemoteEndPoint = _endPoint};
                                                  sArgs.Completed +=
                                                      new EventHandler<SocketAsyncEventArgs>(sArgs_Completed);
                                                  sArgs.SetBuffer(buffer, 0, buffer.Length);
                                                  sArgs.UserToken = buffer;
                                                  _socket.SendAsync(sArgs);
                                              }
                                          };
            _socket.ConnectAsync(sArgsConnect);
        }
开发者ID:Anheledir,项目名称:authenticator-plus,代码行数:28,代码来源:NtpClient.cs


示例19: ConnectAsync

        public override bool ConnectAsync(TimeSpan timeout, TransportAsyncCallbackArgs callbackArgs)
        {
            // TODO: set socket connect timeout to timeout
            this.callbackArgs = callbackArgs;
            DnsEndPoint dnsEndPoint = new DnsEndPoint(this.transportSettings.Host, this.transportSettings.Port);

            SocketAsyncEventArgs connectEventArgs = new SocketAsyncEventArgs();
            connectEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(OnConnectComplete);
            connectEventArgs.RemoteEndPoint = dnsEndPoint;
            connectEventArgs.UserToken = this;

#if MONOANDROID
            // Work around for Mono issue: https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/171
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            bool connectResult = socket.ConnectAsync(connectEventArgs);
#else
            // On Linux platform, socket connections are allowed to be initiated on the socket instance 
            // with hostname due to multiple IP address DNS resolution possibility.
            // They suggest either using static Connect API or IP address directly.
            bool connectResult = Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, connectEventArgs);
#endif
            if (connectResult)
            {
                return true;
            }
            else
            {
                this.Complete(connectEventArgs, true);
                return false;
            }
        }
开发者ID:Azure,项目名称:azure-amqp,代码行数:31,代码来源:TcpTransportInitiator.cs


示例20: ResolveDNSAsync

 public void ResolveDNSAsync(string host, int port)
 {
     if (!string.IsNullOrEmpty(host))
     {
         DnsEndPoint endPoint = new DnsEndPoint(host, 80);
         DeviceNetworkInformation.ResolveHostNameAsync(endPoint, DnsResolutionCallback, new object());
     }
 }
开发者ID:VladimirBabiy,项目名称:HelpersAndUtils,代码行数:8,代码来源:Dns.cs



注:本文中的System.Net.DnsEndPoint类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Net.DownloadDataCompletedEventArgs类代码示例发布时间:2022-05-26
下一篇:
C# Net.CredentialCache类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap