Dart.PowerTCP.SslSockets Namespace > Tcp Class : Stream Property |
Returns a SegmentedStream that can be used for advanced streaming operations on the socket.
[Visual Basic]
<BrowsableAttribute(False)>
<DesignerSerializationVisibilityAttribute()>
Public Property Stream As SegmentedStream
[C#]
[BrowsableAttribute(false)]
[DesignerSerializationVisibilityAttribute()]
public SegmentedStream Stream {get; set;}
[C++]
[BrowsableAttribute(false)]
[DesignerSerializationVisibilityAttribute()]
public: __property SegmentedStream* get_Stream();
public: __property void set_Stream(
SegmentedStream* value
);
[C++/CLI]
[BrowsableAttribute(false)]
[DesignerSerializationVisibilityAttribute()]
public:
property SegmentedStream^ Stream {
SegmentedStream^ get();
void set (SegmentedStream^ value);
}
A SegmentedStream object.
Typically, when data needs to be send or received, the Object.Send or Object.Receive methods can be used. However, often advanced streaming operations are required. Two of the most common are reading token-delimited segments and fixed-length segments. To read fixed-length segments, simply create a fixed-size byte array the size of the segment you would like to read. Then use the Object.Stream.Read method, passing in the byte array and true as the fill parameter. Data is read until either all available data has been received, or the array has been completely filled with data. To read token-delimited segments, create an array of characters that you would like to use as a delimiter. Then use the Object.Stream.Read, passing in the delimiter array. Data is read until the delimiter has been reached. If the delimiter is not found, data is read until all data has been received.
Note: The following applies to using the Tcp.Stream property with secure PowerTCP implementations only! In addition, you can change the initialization of this property to change the behavior of the way data is read or written. Since SegmentedStream is a PipeStream type, Object.Stream.CoreStream can be changed to any type of PipeStream. The PowerTCP secure implementation works this way. For example, if you wish to change to secure communications using SSL, you would initlialize the Object.Stream property using an SslStream like so,
PipeStream "combination", enabling SSL communication.
// (This only applies to using the Tcp component to communicate securely.)
tcp1.Stream = new SegmentedStream(new SslStream(new TcpStream(tcp1)));
]]>
And, to switch back to "normal" communications,
PipeStream "combination.
tcp1.Stream = new SegmentedStream(new TcpStream(tcp1));
]]>
Note for Tcp component usage only:Internally, the Tcp component will "scan" this property to link in the Tcp.CertificateReceivedEvent and Tcp.CertificateRequestedEvent, so these events do not need to be explicitly linked in unless you require advanced functionality.
The following example demonstrates connecting implementing the SMTP protocol using the Tcp component's stream interface to send a simple message.
[Visual Basic]
' 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#]
// 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);
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.