public:
bool Poll(int microSeconds, System::Net::Sockets::SelectMode mode);
public bool Poll (int microSeconds, System.Net.Sockets.SelectMode mode);
member this.Poll : int * System.Net.Sockets.SelectMode -> bool
Public Function Poll (microSeconds As Integer, mode As SelectMode) As Boolean
//Creates the Socket for sending data over TCP.
Socket^ s = gcnew Socket( AddressFamily::InterNetwork, SocketType::Stream,
ProtocolType::Tcp );
// Connects to host using IPEndPoint.
s->Connect( EPhost );
if ( !s->Connected )
strRetPage = "Unable to connect to host";
// Use the SelectWrite enumeration to obtain Socket status.
if ( s->Poll( -1, SelectMode::SelectWrite ) )
Console::WriteLine( "This Socket is writable." );
else if ( s->Poll( -1, SelectMode::SelectRead ) )
Console::WriteLine( "This Socket is readable." );
else if ( s->Poll( -1, SelectMode::SelectError ) )
Console::WriteLine( "This Socket has an error." );
//Creates the Socket for sending data over TCP.
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp );
// Connects to host using IPEndPoint.
s.Connect(EPhost);
if (!s.Connected)
strRetPage = "Unable to connect to host";
// Use the SelectWrite enumeration to obtain Socket status.
if(s.Poll(-1, SelectMode.SelectWrite)){
Console.WriteLine("This Socket is writable.");
else if (s.Poll(-1, SelectMode.SelectRead)){
Console.WriteLine("This Socket is readable." );
else if (s.Poll(-1, SelectMode.SelectError)){
Console.WriteLine("This Socket has an error.");
'Creates the Socket for sending data over TCP.
Dim s As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
' Connects to host using IPEndPoint.
s.Connect(EPhost)
If Not s.Connected Then
strRetPage = "Unable to connect to host"
End If
' Use the SelectWrite enumeration to obtain Socket status.
If s.Poll(- 1, SelectMode.SelectWrite) Then
Console.WriteLine("This Socket is writable.")
If s.Poll(- 1, SelectMode.SelectRead) Then
Console.WriteLine(("This Socket is readable. "))
If s.Poll(- 1, SelectMode.SelectError) Then
Console.WriteLine("This Socket has an error.")
End If
End If
End If
方法
Poll
检查 的状态
Socket
。
SelectMode.SelectRead
指定 参数
selectMode
以确定 是否
Socket
可读。 指定
SelectMode.SelectWrite
以确定 是否
Socket
可写。 使用
SelectMode.SelectError
检测错误条件。
Poll
将阻止执行,直到指定的时间段(以
microseconds
、已用 或数据度量)可用。
microSeconds
如果要无限期等待响应,请将 参数设置为负整数。 如果要检查多个套接字的状态,建议使用
Select
方法。
如果收到 ,
SocketException
请使用
SocketException.ErrorCode
属性获取特定的错误代码。 获取此代码后,请参阅
Windows 套接字版本 2 API 错误代码
文档,了解错误的详细说明。
此方法无法检测某些类型的连接问题,例如网络电缆损坏,或者远程主机未正常关闭。 必须尝试发送或接收数据才能检测这些类型的错误。
当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。 有关详细信息,请参阅
.NET Framework 中的网络跟踪
。
public:
bool Poll(TimeSpan timeout, System::Net::Sockets::SelectMode mode);
public bool Poll (TimeSpan timeout, System.Net.Sockets.SelectMode mode);
member this.Poll : TimeSpan * System.Net.Sockets.SelectMode -> bool
Public Function Poll (timeout As TimeSpan, mode As SelectMode) As Boolean