| Visual Basic (Declaration) | |
|---|---|
<BrowsableAttribute(False)> <DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)> Public Property Stream As SegmentedStream | |
| Visual Basic (Usage) | Copy Code |
|---|---|
Dim instance As Tcp Dim value As SegmentedStream instance.Stream = value value = instance.Stream | |
| C# | |
|---|---|
[BrowsableAttribute(false)] [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)] public SegmentedStream Stream {get; set;} | |
| Managed Extensions for C++ | |
|---|---|
[BrowsableAttribute(false)] [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)] public: __property SegmentedStream* get_Stream(); public: __property void set_Stream( SegmentedStream* value ); | |
| C++/CLI | |
|---|---|
[BrowsableAttribute(false)] [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)] public: property SegmentedStream^ Stream { SegmentedStream^ get(); void set ( SegmentedStream^ value); } | |
Property Value
A SegmentedStream object.| Visual Basic | 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 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); | |
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,
// Initialize the Stream property to a new 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,
// Switch back to a non-secure 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.
Target Platforms: Microsoft .NET Framework 2.0
Copy Code