Dart.PowerTCP.SslSockets Namespace > Udp Class > Send Method : Send(String,String,Int32) Method |
Send a datagram to the specified remote address and port.
[Visual Basic]
<DescriptionAttribute("Convert a string into a byte array and send it.")>
Overloads Public Function Send( _
ByVal buffer As String, _
ByVal host As String, _
ByVal port As Integer _
) As Datagram
[C#]
[DescriptionAttribute("Convert a string into a byte array and send it.")]
public Datagram Send(
string buffer,
string host,
int port
);
[C++]
[DescriptionAttribute("Convert a string into a byte array and send it.")]
public: Datagram* Send(
string* buffer,
string* host,
int port
)
[C++/CLI]
[DescriptionAttribute("Convert a string into a byte array and send it.")]
public:
Datagram^ Send(
String^ buffer,
String^ host,
int port
)
A Datagram object encapsulating the datagram sent.
Exception | Description |
---|---|
ArgumentNullException | buffer is null. |
SocketException | The remote address is unknown, invalid, or unable to be resolved. |
ArgumentOutOfRangeException | The remote port is out of the range of valid values. |
Use the Udp.Send method to sent a datagram created from the data contained in buffer to the specified host and port. buffer is converted to a byte array before sending.
A UDP datagram provides little functionality over an IP datagram, adding a port number field which allows multiplexing on the receiving host and checksum field which provides basic error handling. Unlike TCP, UDP datagrams are sent as a unit. If Udp.Send is called 3 times to send 3 datagrams to a host, the receiving host will have to call Receive 3 times. Also, the size of each datagram sent will equal the size of each datagram received by the receiving host. In addition, since UDP is a connectionless protocol, any datagrams sent to the host are not guaranteed to be delivered. Therefore, any required error checking (outside of UDP's checksum implementation) will have to be done by the application-layer protocol.
To send a broadcast datagram, use "255.255.255.255" as the remote address. To sent a multicast datagram, use the multicast group address as the remote address after first joining a multicast group by using Udp.JoinMulitcastGroup.
The following example demonstrates sending some datagrams to an echo server and receiving the datagrams from the echo server.
[Visual Basic]
Dim iterations as Integer = 3
' Listen on the default interface and an ephemeral port.
udp1.Open()
' Send several datagrams
Dim s as String = "test"
Dim i as Integer
For i=0 to iterations
Udp1.send(s, "MyEchoServer", 7)
Next
' receive the echoed datagrams, there should be 3...requiring 3 Udp.Receive calls.
For i=0 to iterations
Dim d as Datagram = Udp1.Receive(s.Length)
Debug.WriteLine(d.ToString())
Next
'* Output
'* ------------------------
'* test
'* test
'* test
'* ------------------------
'*
[C#]
int iterations = 3;
// Listen on the default interface and an ephemeral port.
udp1.Open();
// Send several datagrams
string s = "test";
for(int i=0; i<iterations; i++)
udp1.send(s, "MyEchoServer", 7);
// receive the echoed datagrams, there should be 3...requiring 3 Udp.Receive calls.
for(int i=0; i<iterations; i++)
{
Datagram d = udp1.Receive(s.Length);
Debug.WriteLine(d.ToString());
}
/* Output
* ------------------------
* test
* test
* test
* ------------------------
*/
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Udp Class | Udp Members | Overload List
Send comments on this topic.
Documentation version 1.1.2.0.
© 2008 Dart Communications. All rights reserved.