TcpClient 생성자

정의

TcpClient 클래스의 새 인스턴스를 초기화합니다.

오버로드

TcpClient()

TcpClient 클래스의 새 인스턴스를 초기화합니다.

TcpClient(IPEndPoint)

TcpClient 클래스의 새 인스턴스를 초기화하고 해당 인스턴스를 지정된 로컬 엔드포인트에 바인딩합니다.

TcpClient(AddressFamily)

지정된 패밀리를 사용하여 TcpClient 클래스의 새 인스턴스를 초기화합니다.

TcpClient(String, Int32)

TcpClient 클래스의 새 인스턴스를 초기화하고 지정된 호스트의 지정된 포트에 연결합니다.

TcpClient()

Source:
TCPClient.cs
Source:
TCPClient.cs
Source:
TCPClient.cs

TcpClient 클래스의 새 인스턴스를 초기화합니다.

public:
 TcpClient();
public TcpClient ();
Public Sub New ()

예제

다음 코드 예제에서는 매개 변수가 없는 생성자를 사용하여 새 TcpClient를 만드는 방법을 보여 줍니다.

//Creates a TCPClient using the default constructor.
TcpClient^ tcpClientC = gcnew TcpClient;
//Creates a TCPClient using the default constructor.
TcpClient tcpClientC = new TcpClient ();
'Creates a TCPClient using the default constructor.
Dim tcpClientC As New TcpClient

설명

이 생성자는 새 TcpClient 를 만들고 기본 서비스 공급자가 가장 적절한 로컬 IP 주소 및 포트 번호를 할당할 수 있도록 합니다. 데이터를 보내고 받기 전에 먼저 메서드를 호출 Connect 해야 합니다.

참고

.NET Framework 이 생성자는 IPv4 주소 유형에서만 작동합니다.

참고

애플리케이션에 네트워크 추적을 사용하도록 설정하면 이 멤버에서 추적 정보를 출력합니다. 자세한 내용은 .NET Framework 네트워크 추적을 참조하세요.

추가 정보

적용 대상

TcpClient(IPEndPoint)

Source:
TCPClient.cs
Source:
TCPClient.cs
Source:
TCPClient.cs

TcpClient 클래스의 새 인스턴스를 초기화하고 해당 인스턴스를 지정된 로컬 엔드포인트에 바인딩합니다.

public:
 TcpClient(System::Net::IPEndPoint ^ localEP);
public TcpClient (System.Net.IPEndPoint localEP);
new System.Net.Sockets.TcpClient : System.Net.IPEndPoint -> System.Net.Sockets.TcpClient
Public Sub New (localEP As IPEndPoint)

매개 변수

localEP
IPEndPoint

TCP Socket을 바인딩할 IPEndPoint입니다.

예외

localEP 매개 변수가 null인 경우

예제

다음 코드 예제에서는 로컬 엔드포인트를 사용 하 여 클래스의 TcpClient instance 만드는 방법을 보여 줍니다.

//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.GetHostEntry (Dns.GetHostName ()).AddressList[0];
IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, 0);
TcpClient tcpClientA = new TcpClient (ipLocalEndPoint);
'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)

설명

이 생성자는 새 TcpClient 를 만들고 매개 변수로 IPEndPoint 지정된 에 localEP 바인딩합니다. 이 생성자를 호출하기 전에 데이터를 보내고 받으려는 IP 주소 및 포트 번호를 사용하여 를 만들어야 IPEndPoint 합니다. 연결하고 통신하기 전에 로컬 IP 주소 및 포트 번호를 지정할 필요가 없습니다. 다른 생성자를 사용하여 를 TcpClient 만드는 경우 기본 서비스 공급자는 가장 적절한 로컬 IP 주소 및 포트 번호를 할당합니다.

데이터를 보내고 받기 전에 메서드를 호출 Connect 해야 합니다.

참고

애플리케이션에 네트워크 추적을 사용하도록 설정하면 이 멤버에서 추적 정보를 출력합니다. 자세한 내용은 .NET Framework 네트워크 추적을 참조하세요.

추가 정보

적용 대상

TcpClient(AddressFamily)

Source:
TCPClient.cs
Source:
TCPClient.cs
Source:
TCPClient.cs

지정된 패밀리를 사용하여 TcpClient 클래스의 새 인스턴스를 초기화합니다.

public:
 TcpClient(System::Net::Sockets::AddressFamily family);
public TcpClient (System.Net.Sockets.AddressFamily family);
new System.Net.Sockets.TcpClient : System.Net.Sockets.AddressFamily -> System.Net.Sockets.TcpClient
Public Sub New (family As AddressFamily)

매개 변수

family
AddressFamily

IP 프로토콜의 AddressFamily입니다.

예외

family 매개 변수가 AddressFamily.InterNetwork와 같지 않은 경우

또는

family 매개 변수가 AddressFamily.InterNetworkV6와 같지 않은 경우

예제

다음 코드 예제를 만드는 방법에 설명 합니다 클래스의 TcpClient instance 합니다.

TcpClient^ tcpClientD = gcnew TcpClient( AddressFamily::InterNetwork );
TcpClient tcpClientD = new TcpClient (AddressFamily.InterNetwork);
Dim tcpClientD As New TcpClient(AddressFamily.InterNetwork)

설명

참고

애플리케이션에 네트워크 추적을 사용하도록 설정하면 이 멤버에서 추적 정보를 출력합니다. 자세한 내용은 .NET Framework 네트워크 추적을 참조하세요.

적용 대상

TcpClient(String, Int32)

Source:
TCPClient.cs
Source:
TCPClient.cs
Source:
TCPClient.cs

TcpClient 클래스의 새 인스턴스를 초기화하고 지정된 호스트의 지정된 포트에 연결합니다.

public:
 TcpClient(System::String ^ hostname, int port);
public TcpClient (string hostname, int port);
new System.Net.Sockets.TcpClient : string * int -> System.Net.Sockets.TcpClient
Public Sub New (hostname As String, port As Integer)

매개 변수

hostname
String

연결할 원격 호스트의 DNS 이름입니다.

port
Int32

연결한 원격 호스트의 포트 번호입니다.

예외

hostname 매개 변수가 null인 경우

port 매개 변수가 MinPortMaxPort 사이에 없습니다.

소켓에 액세스할 때 오류가 발생했습니다.

예제

다음 코드 예제에서는 호스트 이름 및 포트 번호를 사용 하 여 클래스의 TcpClient instance 만드는 방법을 보여 줍니다.

// Creates a TCPClient using hostname and port.
TcpClient^ tcpClientB = gcnew TcpClient( "www.contoso.com",11000 );
//Creates a TCPClient using host name and port.
TcpClient tcpClientB = new TcpClient ("www.contoso.com", 11000);
'Creates a TCPClient using hostname and port.

Dim tcpClientB As New TcpClient("www.contoso.com", 11000)

설명

이 생성자는 새 TcpClient 를 만들고 제공된 호스트 이름 및 포트 번호에 대한 동기 연결을 시도합니다. 기본 서비스 공급자는 가장 적절한 로컬 IP 주소 및 포트 번호를 할당합니다. TcpClient 는 연결되거나 실패할 때까지 차단됩니다. 이 생성자를 사용하면 DNS 호스트 이름을 초기화하고, resolve, 편리한 한 단계로 연결할 수 있습니다.

IPv6을 사용하도록 설정하고 TcpClient(String, Int32) 메서드를 호출하여 IPv6 및 IPv4 주소로 확인되는 호스트에 연결하는 경우 IPv4 주소 전에 먼저 IPv6 주소에 대한 연결이 시도됩니다. 호스트가 IPv6 주소에서 수신 대기하지 않는 경우 연결 설정 시간을 지연시키는 효과가 있을 수 있습니다.

참고

가 수신되면 를 SocketException사용하여 SocketException.ErrorCode 특정 오류 코드를 가져옵니다. 이 코드를 가져온 후에는 Windows 소켓 버전 2 API 오류 코드 설명서에서 오류에 대한 자세한 설명을 참조할 수 있습니다.

참고

애플리케이션에 네트워크 추적을 사용하도록 설정하면 이 멤버에서 추적 정보를 출력합니다. 자세한 내용은 .NET Framework 네트워크 추적을 참조하세요.

추가 정보

적용 대상