Dart.PowerTCP.SslSockets Namespace > Udp Class > Receive Method : Receive(Int32) Method |
Receive a datagram, specifying the maximum bytes to receive.
[Visual Basic]
<DescriptionAttribute("Dynamically instantiates a buffer, receives a datagram into it, and returns it.")>
Overloads Public Function Receive( _
ByVal count As Integer _
) As Datagram
[C#]
[DescriptionAttribute("Dynamically instantiates a buffer, receives a datagram into it, and returns it.")]
public Datagram Receive(
int count
);
[C++]
[DescriptionAttribute("Dynamically instantiates a buffer, receives a datagram into it, and returns it.")]
public: Datagram* Receive(
int count
)
[C++/CLI]
[DescriptionAttribute("Dynamically instantiates a buffer, receives a datagram into it, and returns it.")]
public:
Datagram^ Receive(
int count
)
A Datagram object encapsulating the datagram received.
Use the Udp.Receive method to receive a datagram after first calling Open to specify a port/address to listen for datagrams. This method returns a Datagram object encapsulating the datagram received. Buffer contains the actual datagram data. RemoteEndPoint contains the address/port of the remote host from which the datagram was sent.
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 Send is called 3 times to send 3 datagrams to a host, the receiving host will have to call Udp.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.
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.