PowerTCP Mail for .NET
SegmentedStream Class
Members  Example  See Also  Send comments on this topic.
Dart.PowerTCP.Mail Namespace : SegmentedStream Class




Used to provide advanced reading/writing capabilities to Stream-based objects.

Object Model

SegmentedStream Class

Syntax

Visual Basic (Declaration) 
Public Class SegmentedStream 
   Inherits PipeStream
Visual Basic (Usage)Copy Code
Dim instance As SegmentedStream
C# 
public class SegmentedStream : PipeStream 
Managed Extensions for C++ 
public __gc class SegmentedStream : public PipeStream 
C++/CLI 
public ref class SegmentedStream : public PipeStream 

Example

The following example demonstrates connecting implementing the SMTP protocol using the Tcp component's stream interface to send a simple message.
Visual BasicCopy Code
' The following code assumes that good responses are always received from
' the server. More robust code should check each response and handle appropriately.

' Connect to SMTP port
Tcp1.Connect("mail", 25)

' Send the EHLO command
Tcp1.Stream.Write("EHLO myserver\r\n")

' Get response from the server
Dim s As String = Tcp1.Stream.Read()

' Send MAIL FROM command
Tcp1.Stream.Write("MAIL FROM: test@dart.com" + vbCrLf)

' Get response from the server
s = Tcp1.Stream.Read()

' Send RCPT TO command
Tcp1.Stream.Write("RCPT TO: cranford@dart.com" + vbCrLf)

' Get response from the server
s = Tcp1.Stream.Read()

' Send DATA command
Tcp1.Stream.Write("DATA" + vbCrLf)

' Get response from the server
s = Tcp1.Stream.Read()

' Send DATA
Tcp1.Stream.Write("Test Message" + vbCrLf + "." + vbCrLf)

' Receive response from the server
s = Tcp1.Stream.Read()

' Write output
Debug.WriteLine("Operation complete. The following information")
Debug.WriteLine("was reported by the server:")
Debug.WriteLine(s)
C#Copy Code
// The following code assumes that good responses are always received from
// the server. More robust code should check each response and handle appropriately.

// Connect to SMTP port
tcp1.Connect("mail", 25);

// Send the EHLO command
tcp1.Stream.Write("EHLO myserver\r\n");

// Get response from the server
string s = tcp1.Stream.Read();

// Send MAIL FROM command
tcp1.Stream.Write("MAIL FROM: test@dart.com\r\n");

// Get response from the server
s = tcp1.Stream.Read();

// Send RCPT TO command
tcp1.Stream.Write("RCPT TO: cranford@dart.com\r\n");

// Get response from the server
s = tcp1.Stream.Read();

// Send DATA command
tcp1.Stream.Write("DATA\r\n");

// Get response from the server
s = tcp1.Stream.Read();

// Send DATA
tcp1.Stream.Write("Test Message\r\n.\r\n");

// Receive response from the server
s = tcp1.Stream.Read();

// Write output
Debug.WriteLine("Operation complete. The following information");
Debug.WriteLine("was reported by the server:");
Debug.WriteLine(s);

Remarks

SegmentedStream provides a way to read/write a segment of bytes to/from a backing store. To improve performance, SegmentedStream buffers reads and writes to the underlying stream and provides asynchronous read and write capability.

The SegmentedStream object is used within PowerTCP to read/write network data. The following examples further illustrate how SegmentedStream is used:

  • When using the Tcp or Telnet components, the TCP stream is exposed through the Object.Stream property (which is a SegmentedStream object). To write or read directly to the TCP stream, call Object.Stream.Read or Object.Stream.Write.
  • The SegmentedStream object is also used to access the TCP stream when using other Internet components as well. For example, when using the Ftp component, Ftp.Get or Ftp.Put can be called, making accessible a SegmentedStream object. SegmentedStream.Read and SegmentedStream.Write can then be called to read and write directly to the data connection.

Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.IO.Stream
         Dart.PowerTCP.Mail.EnhancedStream
            Dart.PowerTCP.Mail.PipeStream
               Dart.PowerTCP.Mail.SegmentedStream

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.