TcpClient クラスの新しいインスタンスを初期化し、指定したローカル エンドポイントにバインドします。
名前空間: System.Net.Sockets
アセンブリ: System (system.dll 内)
構文
'宣言
Public Sub New ( _
localEP As IPEndPoint _
)
'使用
Dim localEP As IPEndPoint
Dim instance As New TcpClient(localEP)
public TcpClient (
IPEndPoint localEP
)
public:
TcpClient (
IPEndPoint^ localEP
)
public TcpClient (
IPEndPoint localEP
)
public function TcpClient (
localEP : IPEndPoint
)
パラメータ
- localEP
TCP Socket のバインド先の IPEndPoint。
例外
例外の種類 | 条件 |
---|---|
localEP が null 参照 (Visual Basic では Nothing) です。 |
解説
このコンストラクタは、新しい TcpClient を作成し、これを localEP パラメータで指定した IPEndPoint にバインドします。このコンストラクタを呼び出す前に、データの送受信を開始する IP アドレスおよびポート番号を使用して IPEndPoint を作成する必要があります。接続と通信を行う前にローカル IP アドレスおよびポート番号を指定する必要はありません。その他のコンストラクタを使用して TcpClient を作成する場合は、基になるサービス プロバイダが最も適切なローカル IP アドレスおよびポート番号を割り当てます。
このとき、データを送受信する前に、Connect メソッドを呼び出しておく必要があります。
注意
このメンバは、アプリケーションでネットワーク トレースが有効にされている場合にトレース情報を出力します。詳細については、「ネットワークのトレース」を参照してください。
使用例
ローカル エンドポイントを使用して TcpClient クラスのインスタンスを作成する方法を次のコード例に示します。
'Creates a TCPClient using a local endpoint.
Dim ipAddress As IPAddress = Dns.GetHostEntry(Dns.GetHostName()).AddressList(0)
Dim ipLocalEndPoint As New IPEndPoint(ipAddress, 0)
Dim tcpClientA As New TcpClient(ipLocalEndPoint)
//Creates a TCPClient using a local end point.
IPAddress ipAddress = Dns.GetHostEntry (Dns.GetHostName ()).AddressList[0];
IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, 0);
TcpClient tcpClientA = new TcpClient (ipLocalEndPoint);
//Creates a TCPClient using a local end point.
IPAddress^ ipAddress = Dns::Resolve( Dns::GetHostName() )->AddressList[ 0 ];
IPEndPoint^ ipLocalEndPoint = gcnew IPEndPoint( ipAddress,11000 );
TcpClient^ tcpClientA = gcnew TcpClient( ipLocalEndPoint );
//Creates a TCPClient using a local end point.
IPAddress ipAddress =
Dns.Resolve(Dns.GetHostName()).get_AddressList()[0];
IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, 11000);
TcpClient tcpClientA = new TcpClient(ipLocalEndPoint);
プラットフォーム
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
サポート対象 : 2.0、1.1、1.0
.NET Compact Framework
サポート対象 : 2.0、1.0
参照
関連項目
TcpClient クラス
TcpClient メンバ
System.Net.Sockets 名前空間
IPEndPoint クラス
Connect