| Visual Basic (Declaration) | |
|---|---|
Public Function New( _ ByVal stream As Stream, _ ByVal encoding As Encoding _ ) | |
| Visual Basic (Usage) | Copy Code |
|---|---|
Dim stream As Stream Dim encoding As Encoding Dim instance As New SegmentedStream(stream, encoding) | |
Parameters
- stream
- The source stream to Read/Write.
- encoding
- The encoding type to use when working with strings.
The following example demonstrates initializing a new instance of a SegmentedStream object to a TcpStream.
| Visual Basic | Copy Code |
|---|---|
' Connect to a server Tcp1.Connect("atropos", 7) ' Initialize a SegmentedStream to the NetworkStream Dim sstream As New SegmentedStream(new TcpStream(Tcp1)) ' Send data sstream.Write("hello") ' Receive data Dim s As String = sstream.Read() | |
| C# | Copy Code |
|---|---|
// Connect to a server tcp1.Connect("atropos", 7); // Initialize a SegmentedStream to the NetworkStream SegmentedStream sstream = new SegmentedStream(new TcpStream(tcp1)); // Send data sstream.Write("hello"); // Receive data string s = sstream.Read(); | |
Although any type of stream can be used to initialize a SegmentedStream (a FileStream or a MemoryStream, for example) the intended use is to initialize a SegmentedStream with some form of network stream (such as a TcpStream). You will not usually need to create a SegmentedStream object, as the SegmentedStream object currently accessing the TCP stream is made accessible (either as a property of the component, or as an object accessible in an event or returned from a method). For example, if you wish to send/receive data to/from a server using a stream interface, simply use Tcp.Connect to connect to the server and call Tcp.Stream.Write or Tcp.Stream.Read to send/receive data.
Target Platforms: Microsoft .NET Framework 2.0