UdpClient 생성자
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
UdpClient 클래스의 새 인스턴스를 초기화합니다.
오버로드
| Name | Description |
|---|---|
| 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
- Source:
- UDPClient.cs
- Source:
- UDPClient.cs
UdpClient 클래스의 새 인스턴스를 초기화합니다.
public:
UdpClient();
public UdpClient();
Public Sub New ()
예외
소켓에 액세스할 때 오류가 발생했습니다.
예제
다음 예제에서는 매개 변수가 없는 생성자를 사용하여 클래스의 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 경우 인스턴스는 IPv6 대상을 사용하는 연결 메서드 호출로 변경하거나 덮어쓸 수 없는 IPv4 주소 패밀리로 설정됩니다.
메모
수신되는 SocketException경우 특정 오류 코드를 가져오는 데 사용합니다 SocketException.ErrorCode . 이 코드를 가져온 후에는 Windows 소켓 버전 2 API 오류 코드 설명서에서 오류에 대한 자세한 설명을 참조할 수 있습니다.
이 생성자는 소켓 바인딩을 수행하지 않으므로 멀티캐스트 그룹을 조인하는 데 적합하지 않습니다. 또한 IPv4 주소 유형에서만 작동합니다.
적용 대상
UdpClient(Int32)
- Source:
- UDPClient.cs
- Source:
- UDPClient.cs
- 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
통신하려는 로컬 포트 번호입니다.
예외
소켓에 액세스할 때 오류가 발생했습니다.
예제
다음 예제에서는 로컬 포트 번호를 사용하여 클래스의 UdpClient 인스턴스를 만드는 방법을 보여 줍니다.
//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 경우 인스턴스는 IPv6 대상을 사용하는 연결 메서드 호출로 변경하거나 덮어쓸 수 없는 IPv4 주소 패밀리로 설정됩니다.
메모
수신되는 SocketException경우 특정 오류 코드를 가져오는 데 사용합니다 SocketException.ErrorCode . 이 코드를 가져온 후에는 Windows 소켓 버전 2 API 오류 코드 설명서에서 오류에 대한 자세한 설명을 참조할 수 있습니다.
이 생성자는 IPv4 주소 형식에서만 작동합니다.
적용 대상
UdpClient(IPEndPoint)
- Source:
- UDPClient.cs
- Source:
- UDPClient.cs
- 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
IPEndPoint UDP 연결을 바인딩하는 로컬 엔드포인트를 나타내는 값입니다.
예외
localEP은 null입니다.
소켓에 액세스할 때 오류가 발생했습니다.
예제
다음 예제에서는 로컬 엔드포인트를 사용하여 클래스의 UdpClient 인스턴스를 만드는 방법을 보여 줍니다.
//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 경우 인스턴스는 다른 주소 패밀리를 사용하는 연결 메서드 호출에서 변경하거나 덮어쓸 수 없는 매개 변수로 지정된 localEP 주소 패밀리로 설정됩니다.
메모
수신되는 SocketException경우 특정 오류 코드를 가져오는 데 사용합니다 SocketException.ErrorCode . 이 코드를 가져온 후에는 Windows 소켓 버전 2 API 오류 코드 설명서에서 오류에 대한 자세한 설명을 참조할 수 있습니다.
추가 정보
적용 대상
UdpClient(AddressFamily)
- Source:
- UDPClient.cs
- Source:
- UDPClient.cs
- 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 주소 지정 체계를 지정하는 값 중 하나입니다.
예외
family가 아닙니다InterNetwork.InterNetworkV6
소켓에 액세스할 때 오류가 발생했습니다.
설명
매개 변수는 family 수신기가 IP 버전 4 주소(IPv4) 또는 IP 버전 6(IPv6) 주소를 사용하는지 여부를 결정합니다. IPv4 주소를 사용하려면 값을 전달합니다 InterNetwork . IPv6 주소를 사용하려면 값을 전달합니다 InterNetworkV6 . 다른 값을 전달하면 메서드가 을 throw합니다 ArgumentException.
이 생성자를 사용하는 UdpClient 경우 인스턴스는 다른 주소 패밀리를 사용하는 연결 메서드 호출에서 변경하거나 덮어쓸 수 없는 매개 변수로 지정된 family 주소 패밀리로 설정됩니다.
메모
수신되는 SocketException경우 특정 오류 코드를 가져오는 데 사용합니다 SocketException.ErrorCode . 이 코드를 가져온 후에는 Windows 소켓 버전 2 API 오류 코드 설명서에서 오류에 대한 자세한 설명을 참조할 수 있습니다.
UdpClient.UdpClient(AddressFamily) 소켓 바인딩을 수행하지 않으므로 멀티캐스트 그룹을 조인하는 데 적합하지 않습니다.
적용 대상
UdpClient(Int32, AddressFamily)
- Source:
- UDPClient.cs
- Source:
- UDPClient.cs
- 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 주소 지정 체계를 지정하는 값 중 하나입니다.
예외
family가 아닙니다InterNetwork.InterNetworkV6
소켓에 액세스할 때 오류가 발생했습니다.
예제
다음 코드 예제에서는 멀티캐스트 그룹에서 사용할 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 = 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 경우 인스턴스는 다른 주소 패밀리를 사용하는 연결 메서드 호출에서 변경하거나 덮어쓸 수 없는 매개 변수로 지정된 family 주소 패밀리로 설정됩니다.
메모
수신되는 SocketException경우 특정 오류 코드를 가져오는 데 사용합니다 SocketException.ErrorCode . 이 코드를 가져온 후에는 Windows Sockets 버전 2 API 오류 코드 설명서를 참조하여 오류에 대한 자세한 설명을 참조하세요.
적용 대상
UdpClient(String, Int32)
- Source:
- UDPClient.cs
- Source:
- UDPClient.cs
- 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입니다.
소켓에 액세스할 때 오류가 발생했습니다.
예제
다음 예제에서는 호스트 이름 및 포트 번호를 사용 하 여 클래스의 UdpClient 인스턴스를 만드는 방법을 보여 줍니다.
//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 생성자를 초기화하고 및 hostname 매개 변수를 사용하여 원격 호스트를 port 설정합니다. 기본 원격 호스트 설정은 선택 사항입니다. 이 생성자를 사용하는 경우 메서드에 대한 각 호출에서 원격 호스트를 Send 지정할 필요가 없습니다. 기본 원격 호스트를 지정하면 해당 호스트로만 제한됩니다. 언제든지 메서드를 호출하여 기본 원격 호스트를 Connect 변경할 수 있습니다. 메서드 호출에서 원격 호스트를 Send 지정하려면 이 생성자를 사용하지 마세요.
메모
수신되는 SocketException경우 특정 오류 코드를 가져오는 데 사용합니다 SocketException.ErrorCode . 이 코드를 가져온 후에는 Windows 소켓 버전 2 API 오류 코드 설명서에서 오류에 대한 자세한 설명을 참조할 수 있습니다.