UdpClient.Send 메서드

정의

원격 호스트에 UDP 데이터그램을 보냅니다.

오버로드

Send(Byte[], Int32, String, Int32)

지정된 원격 호스트의 지정된 포트에 UDP 데이터그램을 보냅니다.

Send(ReadOnlySpan<Byte>, String, Int32)

지정된 원격 호스트의 지정된 포트에 UDP 데이터그램을 보냅니다.

Send(Byte[], Int32, IPEndPoint)

지정된 원격 엔드포인트에서 호스트에 UDP 데이터그램을 보냅니다.

Send(Byte[], Int32)

원격 호스트에 UDP 데이터그램을 보냅니다.

Send(ReadOnlySpan<Byte>)

원격 호스트에 UDP 데이터그램을 보냅니다.

Send(ReadOnlySpan<Byte>, IPEndPoint)

지정된 원격 엔드포인트에서 호스트에 UDP 데이터그램을 보냅니다.

Send(Byte[], Int32, String, Int32)

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

지정된 원격 호스트의 지정된 포트에 UDP 데이터그램을 보냅니다.

public:
 int Send(cli::array <System::Byte> ^ dgram, int bytes, System::String ^ hostname, int port);
public int Send (byte[] dgram, int bytes, string? hostname, int port);
public int Send (byte[] dgram, int bytes, string hostname, int port);
member this.Send : byte[] * int * string * int -> int
Public Function Send (dgram As Byte(), bytes As Integer, hostname As String, port As Integer) As Integer

매개 변수

dgram
Byte[]

보내려는 UDP 데이터그램을 지정하는 형식 Byte 의 배열이며, 바이트 배열로 표시됩니다.

bytes
Int32

데이터그램의 바이트 수입니다.

hostname
String

데이터그램을 보낼 원격 호스트의 이름입니다.

port
Int32

통신하려는 원격 포트 번호입니다.

반환

보낸 바이트 수입니다.

예외

dgram이(가) null인 경우

UdpClient 에서는 기본 원격 호스트를 이미 설정한 경우

UdpClient가 닫혔습니다.

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

예제

다음 예제는 Send 메서드. 이 예제에서는 호스트 이름과 포트 번호를 사용하여 대상 호스트를 식별합니다.

UdpClient^ udpClient = gcnew UdpClient;

array<Byte>^ sendBytes = Encoding::ASCII->GetBytes( "Is anybody there" );
try
{
   udpClient->Send( sendBytes, sendBytes->Length, "www.contoso.com", 11000 );
}
catch ( Exception^ e ) 
{
   Console::WriteLine( e->ToString() );
}
UdpClient udpClient = new UdpClient();

Byte[] sendBytes = Encoding.ASCII.GetBytes("Is anybody there");
try{
    udpClient.Send(sendBytes, sendBytes.Length, "www.contoso.com", 11000);
}
catch ( Exception e ){
    Console.WriteLine(e.ToString());	
}
Dim udpClient As New UdpClient()

Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there")
Try
   udpClient.Send(sendBytes, sendBytes.Length, "www.contoso.com", 11000)
Catch e As Exception
   Console.WriteLine(e.ToString())
End Try

설명

메서드는 Sendport 매개 변수로 지정된 값으로 데이터그램을 hostname 보내고 성공적으로 전송된 바이트 수를 반환합니다. 매개 변수 값에 대해 "255.255.255.255"를 지정하여 데이터그램을 기본 브로드캐스트 주소로 hostname 보낼 수 있습니다.

다른 브로드캐스트 주소로 데이터그램을 보내려면 메서드를 사용하여 Client 기본 Socket를 가져오고 소켓 옵션을 로 SocketOptionName.Broadcast설정합니다. 클래스를 사용하도록 Socket 되돌리기 수도 있습니다.

참고

메서드를 사용하여 원격 호스트를 이미 설정한 경우 이 메서드에 호스트 Connect 이름 또는 포트 번호를 제공하지 마세요. 이렇게 하면 메서드가 Send 을 throw합니다 SocketException. 를 수신하는 SocketException경우 를 사용하여 SocketException.ErrorCode 특정 오류 코드를 가져옵니다. 이 코드를 가져온 후에는 Windows 소켓 버전 2 API 오류 코드 설명서를 참조하여 오류에 대한 자세한 설명을 확인할 수 있습니다.

추가 정보

적용 대상

Send(ReadOnlySpan<Byte>, String, Int32)

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

지정된 원격 호스트의 지정된 포트에 UDP 데이터그램을 보냅니다.

public:
 int Send(ReadOnlySpan<System::Byte> datagram, System::String ^ hostname, int port);
public int Send (ReadOnlySpan<byte> datagram, string? hostname, int port);
member this.Send : ReadOnlySpan<byte> * string * int -> int
Public Function Send (datagram As ReadOnlySpan(Of Byte), hostname As String, port As Integer) As Integer

매개 변수

datagram
ReadOnlySpan<Byte>

ReadOnlySpan<T> 보낼 UDP 데이터그램을 지정하는 형식 Byte 의 입니다.

hostname
String

데이터그램을 보낼 원격 호스트의 이름입니다.

port
Int32

통신하려는 원격 포트 번호입니다.

반환

보낸 바이트 수입니다.

예외

UdpClient 에서는 기본 원격 호스트를 이미 설정한 경우

UdpClient가 닫혔습니다.

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

적용 대상

Send(Byte[], Int32, IPEndPoint)

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

지정된 원격 엔드포인트에서 호스트에 UDP 데이터그램을 보냅니다.

public:
 int Send(cli::array <System::Byte> ^ dgram, int bytes, System::Net::IPEndPoint ^ endPoint);
public int Send (byte[] dgram, int bytes, System.Net.IPEndPoint? endPoint);
public int Send (byte[] dgram, int bytes, System.Net.IPEndPoint endPoint);
member this.Send : byte[] * int * System.Net.IPEndPoint -> int
Public Function Send (dgram As Byte(), bytes As Integer, endPoint As IPEndPoint) As Integer

매개 변수

dgram
Byte[]

보내려는 UDP 데이터그램을 지정하는 형식 Byte 의 배열이며, 바이트 배열로 표시됩니다.

bytes
Int32

데이터그램의 바이트 수입니다.

endPoint
IPEndPoint

데이터그램을 보낼 호스트 및 포트를 나타내는 IPEndPoint 입니다.

반환

보낸 바이트 수입니다.

예외

dgram이(가) null인 경우

UdpClient 에서 기본 원격 호스트를 이미 설정했습니다.

UdpClient가 닫혀 있습니다.

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

예제

다음 예제는 Send 메서드. 이 예제에서는 를 IPEndPoint 사용하여 대상 호스트를 지정합니다.

UdpClient^ udpClient = gcnew UdpClient;
IPAddress^ ipAddress = Dns::Resolve( "www.contoso.com" )->AddressList[ 0 ];
IPEndPoint^ ipEndPoint = gcnew IPEndPoint( ipAddress,11004 );

array<Byte>^ sendBytes = Encoding::ASCII->GetBytes( "Is anybody there?" );
try
{
   udpClient->Send( sendBytes, sendBytes->Length, ipEndPoint );
}
catch ( Exception^ e ) 
{
   Console::WriteLine( e->ToString() );
}
UdpClient udpClient = new UdpClient();
IPAddress ipAddress = Dns.Resolve("www.contoso.com").AddressList[0];
IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 11004);	

Byte[] sendBytes = Encoding.ASCII.GetBytes("Is anybody there?");
try{
    udpClient.Send(sendBytes, sendBytes.Length, ipEndPoint);
}
catch ( Exception e ){
    Console.WriteLine(e.ToString());	
}
Dim udpClient As New UdpClient()
Dim ipAddress As IPAddress = Dns.Resolve("www.contoso.com").AddressList(0)
Dim ipEndPoint As New IPEndPoint(ipAddress, 11004)

Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there?")
Try
   udpClient.Send(sendBytes, sendBytes.Length, ipEndPoint)
Catch e As Exception
   Console.WriteLine(e.ToString())
End Try

설명

메서드는 Send 지정된 엔드포인트에 데이터그램을 보내고 성공적으로 전송된 바이트 수를 반환합니다. 이 오버로드를 호출하기 전에 먼저 데이터그램이 IPEndPoint 배달될 원격 호스트의 IP 주소 및 포트 번호를 사용하여 을 만들어야 합니다. 의 속성을 IPEndPoint지정하여 기본 브로드캐스트 주소인 255.255.255.255로 데이터그램을 SocketOptionName.BroadcastAddress 보낼 수 있습니다. 이 IPEndPoint를 만든 후 메서드에 Send 매개 변수로 endPoint 전달합니다.

다른 브로드캐스트 주소로 데이터그램을 보내려면 메서드를 사용하여 Client 기본 Socket를 가져오고 소켓 옵션을 로 SocketOptionName.Broadcast설정합니다. 클래스를 사용하도록 Socket 되돌리기 수도 있습니다.

참고

메서드를 사용하여 endPoint 원격 호스트를 이미 설정한 경우 이 메서드에 매개 변수를 Connect 제공하지 마세요. 이렇게 하면 메서드가 Send 을 throw합니다 SocketException. 를 수신하는 SocketException경우 를 사용하여 SocketException.ErrorCode 특정 오류 코드를 가져옵니다. 이 코드를 가져온 후에는 Windows 소켓 버전 2 API 오류 코드 설명서를 참조하여 오류에 대한 자세한 설명을 확인할 수 있습니다.

추가 정보

적용 대상

Send(Byte[], Int32)

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

원격 호스트에 UDP 데이터그램을 보냅니다.

public:
 int Send(cli::array <System::Byte> ^ dgram, int bytes);
public int Send (byte[] dgram, int bytes);
member this.Send : byte[] * int -> int
Public Function Send (dgram As Byte(), bytes As Integer) As Integer

매개 변수

dgram
Byte[]

보내려는 UDP 데이터그램을 지정하는 형식 Byte 의 배열이며, 바이트 배열로 표시됩니다.

bytes
Int32

데이터그램의 바이트 수입니다.

반환

보낸 바이트 수입니다.

예외

dgram이(가) null인 경우

UdpClient 에서는 기본 원격 호스트를 이미 설정한 경우

UdpClient가 닫혔습니다.

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

예제

다음 예제는 Send 메서드. 이 오버로드를 사용하기 전에 기본 원격 호스트를 설정해야 합니다.

UdpClient^ udpClient = gcnew UdpClient( "www.contoso.com",11000 );
array<Byte>^ sendBytes = Encoding::ASCII->GetBytes( "Is anybody there" );
try
{
   udpClient->Send( sendBytes, sendBytes->Length );
}
catch ( Exception^ e ) 
{
   Console::WriteLine( e->ToString() );
}
UdpClient udpClient = new UdpClient("www.contoso.com", 11000);
Byte[] sendBytes = Encoding.ASCII.GetBytes("Is anybody there");
try{
    udpClient.Send(sendBytes, sendBytes.Length);
}
catch ( Exception e ){
    Console.WriteLine( e.ToString());
}
Dim udpClient As New UdpClient("www.contoso.com", 11000)
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there")
Try
   udpClient.Send(sendBytes, sendBytes.Length)
Catch e As Exception
   Console.WriteLine(e.ToString())
End Try

설명

이 오버로드는 메서드에 설정된 원격 호스트로 데이터그램을 Connect 보내고 전송된 바이트 수를 반환합니다. 이 오버로드를 호출하기 전에 를 호출 Connect 하지 않으면 메서드가 Send 을 throw합니다 SocketException. 를 수신하는 SocketException경우 를 사용하여 SocketException.ErrorCode 특정 오류 코드를 가져옵니다. 이 코드를 가져온 후에는 Windows 소켓 버전 2 API 오류 코드 설명서를 참조하여 오류에 대한 자세한 설명을 확인할 수 있습니다.

다른 원격 호스트에 데이터그램을 보내려면 메서드를 호출 Connect 하고 원하는 원격 호스트를 지정해야 합니다. 다른 Send 메서드 오버로드 중 하나를 사용하여 브로드캐스트 주소로 데이터그램을 보냅니다.

추가 정보

적용 대상

Send(ReadOnlySpan<Byte>)

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

원격 호스트에 UDP 데이터그램을 보냅니다.

public:
 int Send(ReadOnlySpan<System::Byte> datagram);
public int Send (ReadOnlySpan<byte> datagram);
member this.Send : ReadOnlySpan<byte> -> int
Public Function Send (datagram As ReadOnlySpan(Of Byte)) As Integer

매개 변수

datagram
ReadOnlySpan<Byte>

ReadOnlySpan<T> 보낼 UDP 데이터그램을 지정하는 형식 Byte 의 입니다.

반환

보낸 바이트 수입니다.

예외

UdpClient 기본 원격 호스트를 설정하지 않았습니다.

UdpClient가 닫혔습니다.

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

적용 대상

Send(ReadOnlySpan<Byte>, IPEndPoint)

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

지정된 원격 엔드포인트에서 호스트에 UDP 데이터그램을 보냅니다.

public:
 int Send(ReadOnlySpan<System::Byte> datagram, System::Net::IPEndPoint ^ endPoint);
public int Send (ReadOnlySpan<byte> datagram, System.Net.IPEndPoint? endPoint);
member this.Send : ReadOnlySpan<byte> * System.Net.IPEndPoint -> int
Public Function Send (datagram As ReadOnlySpan(Of Byte), endPoint As IPEndPoint) As Integer

매개 변수

datagram
ReadOnlySpan<Byte>

ReadOnlySpan<T> 보낼 UDP 데이터그램을 지정하는 형식 Byte 의 입니다.

endPoint
IPEndPoint

데이터그램을 보낼 호스트 및 포트를 나타내는 IPEndPoint 입니다.

반환

보낸 바이트 수입니다.

예외

UdpClient 은 이미 기본 원격 호스트를 설정했으며 가 endPoint 아닙니다 null.

UdpClient가 닫혀 있습니다.

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

적용 대상