See Also

DatagramEventArgs Members  | Dart.PowerTCP.EmailValidation Namespace

Requirements

Namespace: Dart.PowerTCP.EmailValidation

Platforms: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP, Windows Server 2003, Windows Vista

Assembly: Dart.PowerTCP.EmailValidation (in Dart.PowerTCP.EmailValidation.dll)

Language

Visual Basic

C#

C++

C++/CLI

Show All

See Also Requirements Languages PowerTCP Email Validation for .NET

DatagramEventArgs Class

Dart.PowerTCP.EmailValidation Namespace : DatagramEventArgs Class

Provides data for any event where datagrams are sent or received.

For a list of all members of this type, see DatagramEventArgs members.

Object Model


Inheritance Hierarchy

System.Object
   System.EventArgs
      Dart.PowerTCP.EmailValidation.DatagramEventArgs

Syntax

[Visual Basic]
Public Class DatagramEventArgs    Inherits EventArgs
[C#]
public class DatagramEventArgs : EventArgs
[C++]
public __gc class DatagramEventArgs : public EventArgs
[C++/CLI]
public ref class DatagramEventArgs : public EventArgs

Remarks

A DatagramEventArgs object is passed as a parameter to all events that report the transfer of datagrams. This object contains a Datagram object that references the data sent/received.

If your code causes an exception, it would be returned to the handling event without you seeing it. To preclude such a condition, you should ALWAYS use a try/ catch block around your event-handling code.

Example

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);
}
                

Requirements

Namespace: Dart.PowerTCP.EmailValidation

Platforms: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP, Windows Server 2003, Windows Vista

Assembly: Dart.PowerTCP.EmailValidation (in Dart.PowerTCP.EmailValidation.dll)

See Also

DatagramEventArgs Members  | Dart.PowerTCP.EmailValidation Namespace

 

Send comments on this topic.

Documentation version 1.0.3.0.

© 2008 Dart Communications.  All rights reserved.