当前位置: 首页>>代码示例>>C#>>正文


C# Net.DnsEndPoint类代码示例

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


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


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