SocketType 列挙体
アセンブリ: System (system.dll 内)

Public Enumeration SocketType


データを送受信するには、AddressFamily、SocketType、および ProtocolType を使用して Socket を作成しておく必要があります。このとき、SocketType 列挙値は、開く Socket の種類を定義するいくつかのオプションを提供します。
![]() |
---|
SocketType は、どの ProtocolType が AddressFamily 内で使用されるかを暗黙的に示すことがあります。たとえば SocketType が Dgram の場合、ProtocolType は常に Udp です。SocketType が Stream の場合、ProtocolType は常に Tcp です。互換性のない組み合わせで Socket を作成しようとすると、Socket は SocketException をスローします。 |

Stream の列挙されたメンバを、Socket コンストラクタへのパラメータとして使用する例を次に示します。
'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.") Else If s.Poll(- 1, SelectMode.SelectRead) Then Console.WriteLine(("This Socket is readable. ")) Else If s.Poll(- 1, SelectMode.SelectError) Then Console.WriteLine("This Socket has an error.") End If End If
//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. 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.get_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 should not print." + "Because this is not a listening Socket," + " no incoming connecton requests are expected. "); } else { if (s.Poll(-1, SelectMode.SelectError)) { Console.WriteLine("This Socket has an error."); } } }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- SocketType 列挙体のページへのリンク