本文整理汇总了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;
}
});
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}
}
示例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);
}
示例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()));
}
}
示例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;
}
示例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);
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}