UdpClient 생성자

정의

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

오버로드

UdpClient()

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

UdpClient(Int32)

UdpClient 클래스의 새 인스턴스를 초기화하고 해당 인스턴스를 제공되는 로컬 포트 번호에 바인딩합니다.

UdpClient(IPEndPoint)

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

UdpClient(AddressFamily)

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

UdpClient(Int32, AddressFamily)

UdpClient 클래스의 새 인스턴스를 초기화하고 해당 인스턴스를 제공되는 로컬 포트 번호에 바인딩합니다.

UdpClient(String, Int32)

UdpClient 클래스의 새 인스턴스를 초기화하고 기본 원격 호스트를 설정합니다.

UdpClient()

Source:
UDPClient.cs
Source:
UDPClient.cs
Source:
UDPClient.cs

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

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

예외

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

예제

다음 예제에서는 매개 변수 없는 생성자를 사용 하 여 클래스의 UdpClient instance 만드는 방법을 보여 줍니다.

//Creates an instance of the UdpClient class using the default constructor.
UdpClient^ udpClient = gcnew UdpClient;
//Creates an instance of the UdpClient class using the default constructor.
UdpClient udpClient = new UdpClient();
'Creates an instance of the UdpClient class using the default constructor.
Dim udpClient As New UdpClient()

설명

이 생성자는 새 UdpClient 를 만들고 기본 서비스 공급자가 가장 적절한 로컬 IPv4 주소 및 포트 번호를 할당할 수 있도록 합니다. 이 생성자를 사용하는 UdpClient 경우 instance IPv6 대상을 사용하여 연결 메서드 호출로 변경하거나 덮어쓸 수 없는 IPv4 주소 패밀리로 설정됩니다.

참고

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

이 생성자는 소켓 바인딩을 수행하지 않으므로 멀티캐스트 그룹에 조인하기에 적합하지 않습니다. 또한 IPv4 주소 유형에서만 작동합니다.

적용 대상

UdpClient(Int32)

Source:
UDPClient.cs
Source:
UDPClient.cs
Source:
UDPClient.cs

UdpClient 클래스의 새 인스턴스를 초기화하고 해당 인스턴스를 제공되는 로컬 포트 번호에 바인딩합니다.

public:
 UdpClient(int port);
public UdpClient (int port);
new System.Net.Sockets.UdpClient : int -> System.Net.Sockets.UdpClient
Public Sub New (port As Integer)

매개 변수

port
Int32

통신할 로컬 포트 번호입니다.

예외

port 매개 변수가 MaxPort보다 크거나 MinPort보다 작은 경우

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

예제

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

//Creates an instance of the UdpClient class to listen on
// the default interface using a particular port.
try
{
   UdpClient^ udpClient = gcnew UdpClient( 11000 );
}
catch ( Exception^ e ) 
{
   Console::WriteLine( e->ToString() );
}
//Creates an instance of the UdpClient class to listen on
// the default interface using a particular port.
try{
         UdpClient udpClient = new UdpClient(11000);
}
catch (Exception e ) {
          Console.WriteLine(e.ToString());
  }
'Creates an instance of the UdpClient class to listen on 
'the default interface using a particular port.
Try
   Dim udpClient As New UdpClient(11000)
Catch e As Exception
   Console.WriteLine(e.ToString())
End Try

설명

이 생성자는 기본 을 Socket 만들고 통신하려는 포트 번호에 바인딩합니다. 로컬 포트 번호 설정에만 관심이 있는 경우 이 생성자를 사용합니다. 기본 서비스 공급자는 로컬 IP 주소를 할당합니다. 생성자에 0을 전달하면 기본 서비스 공급자가 포트 번호를 할당합니다. 이 생성자를 사용하는 UdpClient 경우 instance IPv6 대상을 사용하여 연결 메서드 호출로 변경하거나 덮어쓸 수 없는 IPv4 주소 패밀리로 설정됩니다.

참고

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

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

적용 대상

UdpClient(IPEndPoint)

Source:
UDPClient.cs
Source:
UDPClient.cs
Source:
UDPClient.cs

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

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

매개 변수

localEP
IPEndPoint

UDP 연결을 바인딩할 로컬 엔드포인트를 나타내는 IPEndPoint입니다.

예외

localEP이(가) null인 경우

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

예제

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

//Creates an instance of the UdpClient class using a local endpoint.
IPAddress^ ipAddress = Dns::Resolve( Dns::GetHostName() )->AddressList[ 0 ];
IPEndPoint^ ipLocalEndPoint = gcnew IPEndPoint( ipAddress,11000 );

try
{
   UdpClient^ udpClient = gcnew UdpClient( ipLocalEndPoint );
}
catch ( Exception^ e ) 
{
   Console::WriteLine( e->ToString() );
}

//Creates an instance of the UdpClient class using a local endpoint.
 IPAddress ipAddress = Dns.Resolve(Dns.GetHostName()).AddressList[0];
 IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, 11000);

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

Try
   Dim udpClient As New UdpClient(ipLocalEndPoint)
Catch e As Exception
   Console.WriteLine(e.ToString())
End Try

설명

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

이 생성자를 사용하는 경우 다른 주소 패밀리를 사용하는 UdpClient connect 메서드 호출에서 변경하거나 덮어쓸 수 없는 매개 변수로 지정된 localEP 주소 패밀리로 instance 설정됩니다.

참고

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

추가 정보

적용 대상

UdpClient(AddressFamily)

Source:
UDPClient.cs
Source:
UDPClient.cs
Source:
UDPClient.cs

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

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

매개 변수

family
AddressFamily

소켓의 주소 지정 체계를 지정하는 AddressFamily 값 중 하나입니다.

예외

familyInterNetwork 또는 InterNetworkV6이 아닌 경우

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

설명

매개 변수는 family 수신기가 IP 버전 4 주소(IPv4) 또는 IP 버전 6(IPv6) 주소를 사용하는지 여부를 결정합니다. IPv4 주소를 사용하려면 값을 전달합니다 InterNetwork . IPv6 주소를 사용하려면 값을 전달합니다 InterNetworkV6 . 다른 값을 전달하면 메서드가 을 throw합니다 ArgumentException.

이 생성자를 사용하는 경우 다른 주소 패밀리를 사용하는 UdpClient connect 메서드 호출에서 변경하거나 덮어쓸 수 없는 매개 변수로 지정된 family 주소 패밀리로 instance 설정됩니다.

참고

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

UdpClient.UdpClient(AddressFamily) 소켓 바인딩을 수행하지 않으므로 멀티캐스트 그룹에 조인하기에 적합하지 않습니다.

적용 대상

UdpClient(Int32, AddressFamily)

Source:
UDPClient.cs
Source:
UDPClient.cs
Source:
UDPClient.cs

UdpClient 클래스의 새 인스턴스를 초기화하고 해당 인스턴스를 제공되는 로컬 포트 번호에 바인딩합니다.

public:
 UdpClient(int port, System::Net::Sockets::AddressFamily family);
public UdpClient (int port, System.Net.Sockets.AddressFamily family);
new System.Net.Sockets.UdpClient : int * System.Net.Sockets.AddressFamily -> System.Net.Sockets.UdpClient
Public Sub New (port As Integer, family As AddressFamily)

매개 변수

port
Int32

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

family
AddressFamily

소켓의 주소 지정 체계를 지정하는 AddressFamily 값 중 하나입니다.

예외

familyInterNetwork 또는 InterNetworkV6이 아닌 경우

portMaxPort보다 크거나 MinPort보다 작습니다.

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

예제

다음 코드 예제에서는 멀티캐스트 그룹에서 사용할 UDP 클라이언트를 만드는 방법을 보여 있습니다.

// Bind and listen on port 2000. This constructor creates a socket
// and binds it to the port on which to receive data. The family
// parameter specifies that this connection uses an IPv6 address.
clientOriginator = gcnew UdpClient( 2000,AddressFamily::InterNetworkV6 );

// Join or create a multicast group. The multicast address ranges
// to use are specified in RFC#2375. You are free to use
// different addresses.
// Transform the String* address into the internal format.
m_GrpAddr = IPAddress::Parse( "FF01::1" );

// Display the multicast address used.
Console::WriteLine( "Multicast Address: [ {0}]", m_GrpAddr );

// Exercise the use of the IPv6MulticastOption.
Console::WriteLine( "Instantiate IPv6MulticastOption(IPAddress)" );

// Instantiate IPv6MulticastOption using one of the
// overloaded constructors.
IPv6MulticastOption^ ipv6MulticastOption = gcnew IPv6MulticastOption( m_GrpAddr );

// Store the IPAdress multicast options.
IPAddress^ group = ipv6MulticastOption->Group;
__int64 interfaceIndex = ipv6MulticastOption->InterfaceIndex;

// Display IPv6MulticastOption properties.
Console::WriteLine( "IPv6MulticastOption::Group: [ {0}]", group );
Console::WriteLine( "IPv6MulticastOption::InterfaceIndex: [ {0}]", interfaceIndex );

// Instantiate IPv6MulticastOption using another
// overloaded constructor.
IPv6MulticastOption^ ipv6MulticastOption2 = gcnew IPv6MulticastOption( group,interfaceIndex );

// Store the IPAdress multicast options.
group = ipv6MulticastOption2->Group;
interfaceIndex = ipv6MulticastOption2->InterfaceIndex;

// Display the IPv6MulticastOption2 properties.
Console::WriteLine( "IPv6MulticastOption::Group: [ {0} ]", group );
Console::WriteLine( "IPv6MulticastOption::InterfaceIndex: [ {0} ]", interfaceIndex );

// Join the specified multicast group using one of the
// JoinMulticastGroup overloaded methods.
clientOriginator->JoinMulticastGroup( (int)interfaceIndex, group );

// Define the endpoint data port. Note that this port number
// must match the ClientTarget UDP port number which is the
// port on which the ClientTarget is receiving data.
m_ClientTargetdest = gcnew IPEndPoint( m_GrpAddr,1000 );

// Bind and listen on port 2000. This constructor creates a socket
// and binds it to the port on which to receive data. The family
// parameter specifies that this connection uses an IPv6 address.
clientOriginator = new UdpClient(2000, AddressFamily.InterNetworkV6);

// Join or create a multicast group. The multicast address ranges
// to use are specified in RFC#2375. You are free to use
// different addresses.

// Transform the string address into the internal format.
m_GrpAddr = IPAddress.Parse("FF01::1");

// Display the multicast address used.
Console.WriteLine("Multicast Address: [" + m_GrpAddr.ToString() + "]");

// Exercise the use of the IPv6MulticastOption.
Console.WriteLine("Instantiate IPv6MulticastOption(IPAddress)");

// Instantiate IPv6MulticastOption using one of the
// overloaded constructors.
IPv6MulticastOption ipv6MulticastOption = new IPv6MulticastOption(m_GrpAddr);

// Store the IPAdress multicast options.
IPAddress group =  ipv6MulticastOption.Group;
long interfaceIndex = ipv6MulticastOption.InterfaceIndex;

// Display IPv6MulticastOption properties.
Console.WriteLine("IPv6MulticastOption.Group: [" + group  + "]");
Console.WriteLine("IPv6MulticastOption.InterfaceIndex: [" + interfaceIndex + "]");



// Instantiate IPv6MulticastOption using another
// overloaded constructor.
IPv6MulticastOption ipv6MulticastOption2 = new IPv6MulticastOption(group, interfaceIndex);

// Store the IPAdress multicast options.
group =  ipv6MulticastOption2.Group;
interfaceIndex = ipv6MulticastOption2.InterfaceIndex;

// Display the IPv6MulticastOption2 properties.
Console.WriteLine("IPv6MulticastOption.Group: [" + group  + "]");
Console.WriteLine("IPv6MulticastOption.InterfaceIndex: [" + interfaceIndex + "]");

// Join the specified multicast group using one of the
// JoinMulticastGroup overloaded methods.
clientOriginator.JoinMulticastGroup((int)interfaceIndex, group);


// Define the endpoint data port. Note that this port number
// must match the ClientTarget UDP port number which is the
// port on which the ClientTarget is receiving data.
m_ClientTargetdest = new IPEndPoint(m_GrpAddr, 1000);
' Bind and listen on port 2000. This constructor creates a socket 
' and binds it to the port on which to receive data. The family 
' parameter specifies that this connection uses an IPv6 address.
clientOriginator = New UdpClient(2000, AddressFamily.InterNetworkV6)

' Join or create a multicast group. The multicast address ranges 
' to use are specified in RFC#2375. You are free to use 
' different addresses.
' Transform the string address into the internal format.
m_GrpAddr = IPAddress.Parse("FF01::1")

' Display the multicast address used.
Console.WriteLine(("Multicast Address: [" + m_GrpAddr.ToString() + "]"))

' Exercise the use of the IPv6MulticastOption.
Console.WriteLine("Instantiate IPv6MulticastOption(IPAddress)")

' Instantiate IPv6MulticastOption using one of the 
' overloaded constructors.
Dim ipv6MulticastOption As New IPv6MulticastOption(m_GrpAddr)

' Store the IPAdress multicast options.
Dim group As IPAddress = ipv6MulticastOption.Group
Dim interfaceIndex As Long = ipv6MulticastOption.InterfaceIndex

' Display IPv6MulticastOption properties.
Console.WriteLine(("IPv6MulticastOption.Group: [" + group.ToString() + "]"))
Console.WriteLine(("IPv6MulticastOption.InterfaceIndex: [" + interfaceIndex.ToString() + "]"))

' Instantiate IPv6MulticastOption using another 
' overloaded constructor.
Dim ipv6MulticastOption2 As New IPv6MulticastOption(group, interfaceIndex)

' Store the IPAdress multicast options.
group = ipv6MulticastOption2.Group
interfaceIndex = ipv6MulticastOption2.InterfaceIndex

' Display the IPv6MulticastOption2 properties.
Console.WriteLine(("IPv6MulticastOption.Group: [" + group.ToString() + "]"))
Console.WriteLine(("IPv6MulticastOption.InterfaceIndex: [" + interfaceIndex.ToString() + "]"))

' Join the specified multicast group using one of the 
' JoinMulticastGroup overloaded methods.
clientOriginator.JoinMulticastGroup(Fix(interfaceIndex), group)

' Define the endpoint data port. Note that this port number
' must match the ClientTarget UDP port number which is the
' port on which the ClientTarget is receiving data.
m_ClientTargetdest = New IPEndPoint(m_GrpAddr, 1000)

설명

이 생성자는 기본 을 Socket 만들고 통신하려는 포트 번호에 바인딩합니다.

매개 변수는 family 수신기가 IP 버전 4 주소(IPv4) 또는 IP 버전 6(IPv6) 주소를 사용하는지 여부를 결정합니다. IPv4 주소를 사용하려면 값을 전달합니다 InterNetwork . IPv6 주소를 사용하려면 값을 전달합니다 InterNetworkV6 . 다른 값을 전달하면 메서드가 을 throw합니다 ArgumentException.

이 생성자를 사용하는 경우 다른 주소 패밀리를 사용하는 UdpClient connect 메서드 호출에서 변경하거나 덮어쓸 수 없는 매개 변수로 지정된 family 주소 패밀리로 instance 설정됩니다.

참고

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

적용 대상

UdpClient(String, Int32)

Source:
UDPClient.cs
Source:
UDPClient.cs
Source:
UDPClient.cs

UdpClient 클래스의 새 인스턴스를 초기화하고 기본 원격 호스트를 설정합니다.

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

매개 변수

hostname
String

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

port
Int32

연결할 원격 포트 번호입니다.

예외

hostname이(가) null인 경우

portMinPortMaxPort 사이에 없는 경우

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

예제

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

//Creates an instance of the UdpClient class with a remote host name and a port number.
try
{
   UdpClient^ udpClient = gcnew UdpClient( "www.contoso.com",11000 );
}
catch ( Exception^ e ) 
{
   Console::WriteLine( e->ToString() );
}

//Creates an instance of the UdpClient class with a remote host name and a port number.
try{
     UdpClient udpClient = new UdpClient("www.contoso.com",11000);
}
catch (Exception e ) {
           Console.WriteLine(e.ToString());
}
'Creates an instance of the UdpClient class with a remote host name and a port number.
Try
   Dim udpClient As New UdpClient("www.contoso.com", 11000)
Catch e As Exception
   Console.WriteLine(e.ToString())
End Try

설명

이 생성자는 새 UdpClient 를 초기화하고 및 port 매개 변수를 사용하여 원격 호스트를 hostname 설정합니다. 기본 원격 호스트 설정은 선택 사항입니다. 이 생성자를 사용하는 경우 메서드에 대한 각 호출에서 원격 호스트를 Send 지정할 필요가 없습니다. 기본 원격 호스트를 지정하면 해당 호스트로만 제한됩니다. 메서드를 호출하여 언제든지 기본 원격 호스트를 Connect 변경할 수 있습니다. 메서드 호출에서 원격 호스트를 Send 지정하려면 이 생성자를 사용하지 마세요.

참고

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

추가 정보

적용 대상