メモ : このコンストラクタは、互換性のために残されています。
指定したポートを待機する TcpListener クラスの新しいインスタンスを初期化します。
名前空間: System.Net.Sockets
アセンブリ: System (system.dll 内)
構文
'宣言
<ObsoleteAttribute("This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead. https://go.microsoft.com/fwlink/?linkid=14202")> _
Public Sub New ( _
port As Integer _
)
'使用
Dim port As Integer
Dim instance As New TcpListener(port)
[ObsoleteAttribute("This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead. https://go.microsoft.com/fwlink/?linkid=14202")]
public TcpListener (
int port
)
[ObsoleteAttribute(L"This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead. https://go.microsoft.com/fwlink/?linkid=14202")]
public:
TcpListener (
int port
)
/** @attribute ObsoleteAttribute("This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead. https://go.microsoft.com/fwlink/?linkid=14202") */
public TcpListener (
int port
)
ObsoleteAttribute("This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead. https://go.microsoft.com/fwlink/?linkid=14202")
public function TcpListener (
port : int
)
パラメータ
- port
受信接続の試行を待機するポート。
例外
例外の種類 | 条件 |
---|---|
解説
このコンストラクタは今後は使用しません。System.Net.Sockets.TcpListener(IPAddress,Int32) コンストラクタまたは System.Net.Sockets.TcpListener(IPEndPoint) コンストラクタを使用します。
このコンストラクタを使用すると、受信接続の試行を待機するポート番号を指定できます。基になるサービス プロバイダは、このコンストラクタを使用して最も適切なネットワーク アドレスを割り当てます。どのローカル ポートを使用してもかまわない場合は、ポート番号を 0 に指定することもできます。この場合、サービス プロバイダは 1024 ~ 5000 の範囲で使用できるポート番号を割り当てます。この方法を使用する場合、LocalEndpoint プロパティを使用することによって、既に割り当てられているローカル ネットワーク アドレスとポート番号を知ることができます。
Start メソッドを呼び出して、受信接続試行の待機を開始します。
使用例
ローカル ポート番号を使用して、TcpListener を作成するコード例を次に示します。
'Creates an instance of the TcpListener class by providing a local port number.
Dim ipAddress As IPAddress = Dns.Resolve("localhost").AddressList(0)
Try
Dim tcpListener As New TcpListener(ipAddress, 13)
Catch e As Exception
Console.WriteLine(e.ToString())
End Try
//Creates an instance of the TcpListener class by providing a local port number.
IPAddress ipAddress = Dns.Resolve("localhost").AddressList[0];
try{
TcpListener tcpListener = new TcpListener(ipAddress, 13);
}
catch ( Exception e ){
Console.WriteLine( e.ToString());
}
//Creates an instance of the TcpListener class by providing a local port number.
IPAddress^ ipAddress = Dns::Resolve( "localhost" )->AddressList[ 0 ];
try
{
TcpListener^ tcpListener = gcnew TcpListener( ipAddress,13 );
}
catch ( Exception^ e )
{
Console::WriteLine( e->ToString() );
}
// Creates an instance of the TcpListener class by
// providing a local port number.
IPAddress ipAddress = (IPAddress)Dns.Resolve(
"localhost").get_AddressList().get_Item(0);
try {
TcpListener tcpListener =
new TcpListener(ipAddress, 13);
}
catch (System.Exception e) {
Console.WriteLine(e.ToString());
}
プラットフォーム
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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 1.0、1.1
2.0 では、互換性のために残されています (コンパイル時に警告)
.NET Compact Framework
サポート対象 : 1.0
2.0 では、互換性のために残されています (コンパイル時に警告)
参照
関連項目
TcpListener クラス
TcpListener メンバ
System.Net.Sockets 名前空間
Start