Share via


TcpListener 생성자

정의

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

오버로드

TcpListener(Int32)
사용되지 않음.
사용되지 않음.
사용되지 않음.
사용되지 않음.

지정된 포트에서 수신하는 TcpListener 클래스의 새 인스턴스를 초기화합니다.

TcpListener(IPEndPoint)

지정된 로컬 엔드포인트를 사용하여 TcpListener 클래스의 새 인스턴스를 초기화합니다.

TcpListener(IPAddress, Int32)

지정된 로컬 IP 주소와 포트 번호에서 들어오는 연결 시도를 수신하는 TcpListener 클래스의 새 인스턴스를 초기화합니다.

TcpListener(Int32)

Source:
TCPListener.cs
Source:
TCPListener.cs
Source:
TCPListener.cs

주의

This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead. https://go.microsoft.com/fwlink/?linkid=14202

주의

This constructor has been deprecated. Use TcpListener(IPAddress localaddr, int port) instead.

주의

This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead. http://go.microsoft.com/fwlink/?linkid=14202

주의

Use TcpListener(IPAddress localaddr, int port).

지정된 포트에서 수신하는 TcpListener 클래스의 새 인스턴스를 초기화합니다.

public:
 TcpListener(int port);
[System.Obsolete("This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead. https://go.microsoft.com/fwlink/?linkid=14202")]
public TcpListener (int port);
[System.Obsolete("This constructor has been deprecated. Use TcpListener(IPAddress localaddr, int port) instead.")]
public TcpListener (int port);
[System.Obsolete("This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public TcpListener (int port);
[System.Obsolete("Use TcpListener(IPAddress localaddr, int port).")]
public TcpListener (int port);
[<System.Obsolete("This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead. https://go.microsoft.com/fwlink/?linkid=14202")>]
new System.Net.Sockets.TcpListener : int -> System.Net.Sockets.TcpListener
[<System.Obsolete("This constructor has been deprecated. Use TcpListener(IPAddress localaddr, int port) instead.")>]
new System.Net.Sockets.TcpListener : int -> System.Net.Sockets.TcpListener
[<System.Obsolete("This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead. http://go.microsoft.com/fwlink/?linkid=14202")>]
new System.Net.Sockets.TcpListener : int -> System.Net.Sockets.TcpListener
[<System.Obsolete("Use TcpListener(IPAddress localaddr, int port).")>]
new System.Net.Sockets.TcpListener : int -> System.Net.Sockets.TcpListener
Public Sub New (port As Integer)

매개 변수

port
Int32

들어오는 연결 시도를 수신하는 데 사용되는 포트입니다.

특성

예외

portMinPortMaxPort 사이에 없는 경우

예제

다음 코드 예제에서는 로컬 포트 번호를 사용하여 를 만듭니다 TcpListener .

//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 = 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.  
   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

설명

이 생성자는 사용되지 않습니다. TcpListener.TcpListener(IPAddress, Int32) 또는 TcpListener.TcpListener(IPEndPoint) 생성자를 사용합니다.

이 생성자를 사용하면 들어오는 연결 시도를 수신 대기할 포트 번호를 지정할 수 있습니다. 이 생성자를 사용하면 기본 서비스 공급자가 가장 적절한 네트워크 주소를 할당합니다. 사용되는 로컬 포트를 신경 쓰지 않는 경우 포트 번호에 대해 0을 지정할 수 있습니다. 이 경우 서비스 공급자는 사용 가능한 임시 포트 번호를 할당합니다. 이 방법을 사용하는 경우 속성을 사용하여 할당된 로컬 네트워크 주소 및 포트 번호를 검색할 LocalEndpoint 수 있습니다.

메서드를 Start 호출하여 들어오는 연결 시도에 대한 수신 대기를 시작합니다.

추가 정보

적용 대상

TcpListener(IPEndPoint)

Source:
TCPListener.cs
Source:
TCPListener.cs
Source:
TCPListener.cs

지정된 로컬 엔드포인트를 사용하여 TcpListener 클래스의 새 인스턴스를 초기화합니다.

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

매개 변수

localEP
IPEndPoint

IPEndPoint수신기를 바인딩할 로컬 엔드포인트를 나타내는 Socket입니다.

예외

localEP이(가) null인 경우

예제

다음 코드 예제에서는 로컬 엔드포인트를 사용 하 여 클래스의 TcpListener instance 만듭니다.

//Creates an instance of the TcpListener class by providing a local endpoint.

IPAddress^ ipAddress = Dns::Resolve( Dns::GetHostName() )->AddressList[ 0 ];
IPEndPoint^ ipLocalEndPoint = gcnew IPEndPoint( ipAddress,11000 );

try
{
   TcpListener^ tcpListener = gcnew TcpListener( ipLocalEndPoint );
}
catch ( Exception^ e ) 
{
   Console::WriteLine( e->ToString() );
}
//Creates an instance of the TcpListener class by providing a local endpoint.

IPAddress ipAddress = Dns.Resolve(Dns.GetHostName()).AddressList[0];
IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, 11000);

try{
    TcpListener tcpListener = new TcpListener(ipLocalEndPoint);
}
catch ( Exception e ){
    Console.WriteLine( e.ToString());
}
'Creates an instance of the TcpListener class by providing a local endpoint.
Dim ipAddress As IPAddress = Dns.Resolve(Dns.GetHostName()).AddressList(0)
Dim ipLocalEndPoint As New IPEndPoint(ipAddress, 11000)

Try
   Dim tcpListener As New TcpListener(ipLocalEndPoint)
Catch e As Exception
   Console.WriteLine(e.ToString())
End Try

설명

이 생성자를 사용하면 들어오는 연결 시도를 수신 대기할 로컬 IP 주소 및 포트 번호를 지정할 수 있습니다. 이 생성자를 사용하기 전에 원하는 로컬 IP 주소 및 포트 번호를 사용하여 을 만들어야 IPEndPoint 합니다. 매개 변수로 생성자에 전달 IPEndPoint 합니다 localEP .

할당된 로컬 주소를 신경 쓰지 않는 경우 를 주소 매개 변수로 사용하여 IPAddress.Any 만들 IPEndPoint 수 있으며 기본 서비스 공급자가 가장 적절한 네트워크 주소를 할당합니다. 이렇게 하면 여러 네트워크 인터페이스가 있는 경우 애플리케이션을 간소화 하는 데 도움이 될 수 있습니다. 사용되는 로컬 포트를 신경 쓰지 않는 경우 포트 번호에 0을 IPEndPoint 사용하여 를 만들 수 있습니다. 이 경우 서비스 공급자는 사용 가능한 임시 포트 번호를 할당합니다. 이 방법을 사용하는 경우 속성을 사용하여 할당된 로컬 네트워크 주소 및 포트 번호를 검색할 LocalEndpoint 수 있습니다.

메서드를 Start 호출하여 들어오는 연결 시도에 대한 수신 대기를 시작합니다.

참고

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

추가 정보

적용 대상

TcpListener(IPAddress, Int32)

Source:
TCPListener.cs
Source:
TCPListener.cs
Source:
TCPListener.cs

지정된 로컬 IP 주소와 포트 번호에서 들어오는 연결 시도를 수신하는 TcpListener 클래스의 새 인스턴스를 초기화합니다.

public:
 TcpListener(System::Net::IPAddress ^ localaddr, int port);
public TcpListener (System.Net.IPAddress localaddr, int port);
new System.Net.Sockets.TcpListener : System.Net.IPAddress * int -> System.Net.Sockets.TcpListener
Public Sub New (localaddr As IPAddress, port As Integer)

매개 변수

localaddr
IPAddress

로컬 IP 주소를 나타내는 IPAddress입니다.

port
Int32

들어오는 연결 시도를 수신하는 데 사용되는 포트입니다.

예외

localaddr이(가) null인 경우

portMinPortMaxPort 사이에 없는 경우

예제

다음 코드 예제에서는 로컬 IP 주소 및 포트 번호를 사용 하 여 클래스의 TcpListener instance 만듭니다.

//Creates an instance of the TcpListener class by providing a local IP address and 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 IP address and 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 IP address and 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

설명

이 생성자를 사용하면 들어오는 연결 시도를 수신 대기할 로컬 IP 주소 및 포트 번호를 지정할 수 있습니다. 이 생성자를 호출하기 전에 먼저 원하는 로컬 주소를 사용하여 을 만들어야 IPAddress 합니다. 매개 변수로 생성자에 전달 IPAddress 합니다 localaddr . 할당된 로컬 주소를 신경 쓰지 않는 경우 매개 변수를 localaddr 지정 IPAddress.Any 하고 기본 서비스 공급자가 가장 적절한 네트워크 주소를 할당합니다. 이렇게 하면 여러 네트워크 인터페이스가 있는 경우 애플리케이션을 간소화 하는 데 도움이 될 수 있습니다. 사용되는 로컬 포트를 신경 쓰지 않는 경우 포트 번호에 대해 0을 지정할 수 있습니다. 이 경우 서비스 공급자는 1024에서 65535 사이의 사용 가능한 포트 번호를 할당합니다. 이 방법을 사용하는 경우 속성을 사용하여 할당된 로컬 네트워크 주소 및 포트 번호를 검색할 LocalEndpoint 수 있습니다.

메서드를 Start 호출하여 들어오는 연결 시도에 대한 수신 대기를 시작합니다.

참고

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

추가 정보

적용 대상