TcpClient.Connectとは? わかりやすく解説

TcpClient.Connect メソッド (String, Int32)

指定されホスト指定されポートクライアント接続します

名前空間: System.Net.Sockets
アセンブリ: System (system.dll 内)
構文構文

例外例外
例外種類条件

ArgumentNullException

hostnamenull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

port が MinPort と MaxPort の間の値ではありません。

SocketException

ソケットへのアクセス中にエラー発生しました詳細については「解説」を参照してください

ObjectDisposedException

TcpClient が閉じてます。

解説解説
使用例使用例

ホスト名ポート番号使用してリモート ホスト接続するコード例次に示します

'Uses a host name and port number to establish a socket connection.
Dim tcpClient As New TcpClient()

   tcpClient.Connect("www.contoso.com", 11002)

//Uses a host name and port number to establish a socket connection.
TcpClient tcpClient = new TcpClient ();
tcpClient.Connect ("www.contoso.com", 11002);

//Uses a host name and port number to establish a socket connection.
TcpClient^ tcpClient = gcnew TcpClient;
tcpClient->Connect( "www.contoso.com", 11002 );

//Uses a host name and port number to establish a socket connection.
TcpClient tcpClient = new TcpClient();
tcpClient.Connect("www.contoso.com", 11002);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TcpClient クラス
TcpClient メンバ
System.Net.Sockets 名前空間
Connect
GetStream

TcpClient.Connect メソッド (IPEndPoint)

指定されリモート ネットワーク エンドポイント使用してリモート TCP ホストクライアント接続します

名前空間: System.Net.Sockets
アセンブリ: System (system.dll 内)
構文構文

Public Sub Connect ( _
    remoteEP As IPEndPoint _
)
Dim instance As TcpClient
Dim remoteEP As IPEndPoint

instance.Connect(remoteEP)
public void Connect (
    IPEndPoint remoteEP
)
public:
void Connect (
    IPEndPoint^ remoteEP
)
public void Connect (
    IPEndPoint remoteEP
)
public function Connect (
    remoteEP : IPEndPoint
)

パラメータ

remoteEP

接続先の IPEndPoint。

例外例外
例外種類条件

ArgumentNullException

remoteEpnull 参照 (Visual Basic では Nothing) です。

SocketException

ソケットへのアクセス中にエラー発生しました詳細については「解説」を参照してください

ObjectDisposedException

TcpClient が閉じてます。

解説解説
使用例使用例

IPEndPoint使用してリモート ホスト接続するコード例次に示します

'Uses a remote endpoint to establish a socket connection.
Dim tcpClient As New TcpClient
Dim ipAddress As IPAddress = Dns.GetHostEntry("www.contoso.com").AddressList(0)
Dim ipEndPoint As New IPEndPoint(ipAddress,
 11004)

tcpClient.Connect(ipEndPoint)

//Uses a remote endpoint to establish a socket connection.
TcpClient tcpClient = new TcpClient ();
IPAddress ipAddress = Dns.GetHostEntry ("www.contoso.com").AddressList[0];
IPEndPoint ipEndPoint = new IPEndPoint (ipAddress, 11004);

tcpClient.Connect (ipEndPoint);

//Uses a remote end point to establish a socket connection.
TcpClient^ tcpClient = gcnew TcpClient;
IPAddress^ ipAddress = Dns::Resolve( "www.contoso.com" )->AddressList[
 0 ];
IPEndPoint^ ipEndPoint = gcnew IPEndPoint( ipAddress,11004 );
tcpClient->Connect( ipEndPoint );

//Uses a remote end point to establish a socket connection.
TcpClient tcpClient = new TcpClient();
IPAddress ipAddress =
    Dns.Resolve("www.contoso.com").get_AddressList()[0];
IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 11004);

tcpClient.Connect(ipEndPoint);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TcpClient クラス
TcpClient メンバ
System.Net.Sockets 名前空間
IPEndPoint クラス
GetStream

TcpClient.Connect メソッド (IPAddress, Int32)

指定されIP アドレスポート番号使用してクライアントリモート TCP ホスト接続します

名前空間: System.Net.Sockets
アセンブリ: System (system.dll 内)
構文構文

例外例外
例外種類条件

ArgumentNullException

address パラメータnull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

port が MinPort と MaxPort の間の値ではありません。

SocketException

ソケットへのアクセス中にエラー発生しました詳細については「解説」を参照してください

ObjectDisposedException

TcpClient が閉じてます。

解説解説
使用例使用例

IP アドレスポート番号使用してリモート ホスト接続するコード例次に示します

'Uses the IP address and port number to establish a socket connection.
Dim tcpClient As New TcpClient
Dim ipAddress As IPAddress = Dns.GetHostEntry("www.contoso.com").AddressList(0)
tcpClient.Connect(ipAddress, 11003)
//Uses the IP address and port number to establish a socket connection.
TcpClient tcpClient = new TcpClient ();
IPAddress ipAddress = Dns.GetHostEntry ("www.contoso.com").AddressList[0];

tcpClient.Connect (ipAddress, 11003);

//Uses the IP address and port number to establish a socket connection.
TcpClient^ tcpClient = gcnew TcpClient;
IPAddress^ ipAddress = Dns::Resolve( "www.contoso.com" )->AddressList[
 0 ];
tcpClient->Connect( ipAddress, 11003 );

//Uses the IP address and port number to establish a socket
// connection.
TcpClient tcpClient = new TcpClient();
IPAddress ipAddress =
    Dns.Resolve("www.contoso.com").get_AddressList()[0];

tcpClient.Connect(ipAddress, 11003);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TcpClient クラス
TcpClient メンバ
System.Net.Sockets 名前空間
GetStream

TcpClient.Connect メソッド


TcpClient.Connect メソッド (IPAddress[], Int32)

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

指定されIP アドレスポート番号使用してクライアントリモート TCP ホスト接続します

名前空間: System.Net.Sockets
アセンブリ: System (system.dll 内)
構文構文

Public Sub Connect ( _
    ipAddresses As IPAddress(), _
    port As Integer _
)
Dim instance As TcpClient
Dim ipAddresses As IPAddress()
Dim port As Integer

instance.Connect(ipAddresses, port)
public void Connect (
    IPAddress[] ipAddresses,
    int port
)
public:
void Connect (
    array<IPAddress^>^ ipAddresses, 
    int port
)
public void Connect (
    IPAddress[] ipAddresses, 
    int port
)

パラメータ

ipAddresses

接続ホストIPAddress 配列

port

接続先のポート番号

例外例外
例外種類条件

ArgumentNullException

ipAddresses パラメータnull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

ポート番号無効です。

SocketException

ソケットへのアクセス試みているときにエラー発生しました詳細については「解説」を参照してください

ObjectDisposedException

Socket閉じられています。

SecurityException

コール スタックの上位にある呼び出し元が、要求され操作アクセス許可保持していません。

NotSupportedException

このメソッドは、InterNetwork フラグまたは InterNetworkV6 フラグ使用するソケットで有効です。

解説解説
使用例使用例

IP アドレスポート番号使用してリモート ホスト接続するコード例次に示します

static void DoConnect(string
 host, int port)
{
    // Connect to the specified host.
    TcpClient t = new TcpClient(AddressFamily.InterNetwork);
      
    IPAddress[] IPAddresses = Dns.GetHostAddresses(host);

    Console.WriteLine("Establishing connection to {0}", host);
    t.Connect(IPAddresses, port);

    Console.WriteLine("Connection established");
}
static void DoConnect( String^ host, int
 port )
{
   // Connect to the specified host.
   TcpClient^ t = gcnew TcpClient( AddressFamily::InterNetwork );
   array<IPAddress^>^IPAddresses = Dns::GetHostAddresses( host );
   Console::WriteLine( "Establishing Connection to {0}", host );
   t->Connect( IPAddresses, port );
   Console::WriteLine( "Connection established" );
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TcpClient クラス
TcpClient メンバ
System.Net.Sockets 名前空間
TcpListener


このページでは「.NET Framework クラス ライブラリ リファレンス」からTcpClient.Connectを検索した結果を表示しています。
Weblioに収録されているすべての辞書からTcpClient.Connectを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からTcpClient.Connect を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「TcpClient.Connect」の関連用語

TcpClient.Connectのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TcpClient.Connectのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS