MailBee.NET Objects 4.0

Pop3.LowLevelDataReceived Event

Occurs when data is received from the connected socket.

public event DataTransferEventHandler LowLevelDataReceived;

Event Data

The event handler receives an argument of type DataTransferEventArgs containing data related to this event. The following DataTransferEventArgs properties provide information specific to this event.

Property Description
Data Gets a reference to the data block (chunk) sent or received.
Protocol Gets application-level protocol of the current connection.
RemoteEndPoint Gets a reference to the end point of the server host.
RemoteHostName Gets the host name of the server.
State Gets a reference to the object which was supplied by the developer in state parameter of asynchronous methods of the mailer components.

Remarks

If the transmission channel is encrypted, this event will be raised when any encrypted chunk of data is received. Thus, this event can be used to record the data which is actually received from the network.

The typical use of this property is to calculate the network traffic produced during the POP3 session. SSL encryption increases the length of the transmitted data blocks, thus it's more accurate to calculate traffic by counting the length of data actually transmitted over the network.

If the transmission channel is not encrypted or otherwise scrambled, this property is equivalent to DataReceived.

Example

This sample calculates all incoming traffic from the server during the POP3 session, and prints the result into console.

[C#]
using System;
using MailBee;
using MailBee.Pop3Mail;
using MailBee.Mime;

class Sample
{
    // Total bytes received counter.
    private static int _totalBytes = 0;

    // LowLevelDataReceived event handler.
    private static void OnLowLevelDataReceived(object sender,
        DataTransferEventArgs e)
    {
        // Increment the counter.
        _totalBytes += e.Data.Length;
    }

    // The actual code.
    static void Main(string[] args)
    {
        Pop3 pop = new Pop3();

        // Subscribe to the LowLevelDataReceived event.
        pop.LowLevelDataReceived += new DataTransferEventHandler(OnLowLevelDataReceived);

        // Do something which would produce some network traffic.
        pop.Connect("mail.domain.com");
        pop.Login("jdoe", "secret");
        MailMessageCollection msgs = pop.DownloadMessageHeaders();
        pop.Disconnect();

        // Print the total number of bytes previously received from the server.
        Console.WriteLine(_totalBytes + " bytes received in all");
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.Pop3Mail
Imports MailBee.Mime

Class Sample
    ' Total bytes received counter.
    Private Shared _totalBytes = 0

    ' LowLevelDataReceived event handler.
    Private Shared Sub OnLowLevelDataReceived(ByVal sender As Object, ByVal e As DataTransferEventArgs)
        ' Increment the counter.
        _totalBytes += e.Data.Length
    End Sub

    ' The actual code.
    Shared Sub Main(ByVal args As String())
        Dim pop As New Pop3

        ' Subscribe to the LowLevelDataReceived event.
        AddHandler pop.LowLevelDataReceived, AddressOf OnLowLevelDataReceived

        ' Do something which would produce some network traffic.
        pop.Connect("pop.somehost.com")
        pop.Login("jdoe", "secret")

        Dim msgs As MailMessageCollection
        msgs = pop.DownloadMessageHeaders()
        pop.Disconnect()

        ' Print the total number of bytes previously received from the server.
        Console.WriteLine(_totalBytes & " bytes received in all")
    End Sub
End Class

See Also

Pop3 Class | MailBee.Pop3Mail Namespace | DataReceived