Dart.PowerTCP.SslSockets Namespace > Udp Class : EndReceive Event (Udp) |
Raised when the BeginReceive request completes.
[Visual Basic]
<DescriptionAttribute("Raised when the BeginReceive() request completes")>
<CategoryAttribute("Completion Notification")>
Public Event EndReceive() As DatagramEventHandler
[C#]
[DescriptionAttribute("Raised when the BeginReceive() request completes")]
[CategoryAttribute("Completion Notification")]
public event DatagramEventHandler EndReceive();
[C++]
[DescriptionAttribute("Raised when the BeginReceive() request completes")]
[CategoryAttribute("Completion Notification")]
public: __event DatagramEventHandler* EndReceive();
[C++/CLI]
[DescriptionAttribute("Raised when the BeginReceive() request completes")]
[CategoryAttribute("Completion Notification")]
public:
event DatagramEventHandler^ EndReceive();
The event handler receives an argument of type DatagramEventArgs containing data related to this event. The following DatagramEventArgs properties provide information specific to this event.
Property | Description |
---|---|
Datagram | Gets the Datagram object that represents the datagram for which the event was raised. |
Exception | Gets any exception which occurred during the asynchronous operation. |
State | Gets the object that was included as part of the associated method call. |
This event is raised when the asynchronous method call BeginReceive completes. A DatagramEventArgs object is passed into the event, containing information about the event, such as the datagram received.
If any errors occurred during the asynchronous operation, they would be returned in the DatagramEventArgs object, check Exception to check for any exception.
For more information on using events using PowerTCP.NET within the Visual Studio.NET environment, see the topic, Using Events In PowerTCP.
If you are using the Udp component as a reference, you must create a method to handle the event yourself.
This event MUST be implemented if you are using the BeginReceive method.
The following example demonstrates creating a UDP echo server application which listens for datagrams and echoes them back to the sender.
[Visual Basic]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Listen for datagrams on port 7.
Udp1.Open(7)
' Begin an asynchronous Receive
Dim buffer(Udp1.BufferSize) As Byte
Udp1.BeginReceive(buffer)
End Sub
Private Sub Udp1_EndReceive(ByVal sender As Object, ByVal e As DatagramEventArgs) Handles Udp1.EndReceive
' Check for an Exception
If e.Exception is Nothing Then
' Echo the data back using the Datagram object passed into the event.
' Datagram.Buffer = data received from client
' Datagram.RemoteEndPoint = address/port of client.
Udp1.Send(e.Datagram.Buffer, e.Datagram.RemoteEndPoint)
End If
' Start receiving next
Dim buffer(Udp1.BufferSize) As Byte
Udp1.BeginReceive(buffer)
End Sub
[C#]
private void StartServer()
{
// Listen for datagrams on port 7.
udp1.Open(7);
// Begin an asynchronous Receive
byte[] buffer = new byte[udp1.BufferSize];
udp1.BeginReceive(buffer);
}
private void udp1_EndReceive(object
sender, DatagramEventArgs e)
{
// Check for an exception
if(e.Exception == null)
{
// Echo the data back using the Datagram object passed into the event.
// Datagram.Buffer = data received from client
// Datagram.RemoteEndPoint = address/port of client.
Datagram d = udp1.Send(e.Datagram.Buffer, e.Datagram.RemoteEndPoint);
}
// Start receiving next
byte[] buffer = new byte[udp1.BufferSize];
udp1.BeginReceive(buffer);
}
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Send comments on this topic.
Documentation version 1.1.2.0.
© 2008 Dart Communications. All rights reserved.