| Visual Basic (Declaration) | |
|---|---|
Public Overrides Sub Flush() | |
| Visual Basic (Usage) | Copy Code |
|---|---|
Dim instance As SegmentedStream instance.Flush() | |
| C# | |
|---|---|
public override void Flush() | |
| Managed Extensions for C++ | |
|---|---|
public: void Flush(); override | |
| C++/CLI | |
|---|---|
public: void Flush(); override | |
The following example demonstrates writing data until a delimiter is reached.
| Visual Basic | Copy Code |
|---|---|
' Create test data Dim buffer As Byte() = System.Text.Encoding.Default.GetBytes("acbdefghijklmnopqrstuvwxyz" + vbCrLf) Dim delimiter As Byte() = System.Text.Encoding.Default.GetBytes("ghi") Dim offset As Integer = 0 Dim count As Integer = buffer.Length ' Connect to echo port Tcp1.Connect("atropos", 7) ' Send data until the delimiter is reached. Dim found As Boolean = Tcp1.Stream.Write(buffer, delimiter, offset, count) ' Flush the rest of the data Tcp1.Stream.Flush() ' Recieve data. Dim s As String = Tcp1.Stream.Read() Debug.WriteLine(s) '* Output '* ----------------------- '* abcdef | |
| C# | Copy Code |
|---|---|
// Create test data byte[] buffer = System.Text.Encoding.Default.GetBytes("acbdefghijklmnopqrstuvwxyz\r\n"); byte[] delimiter = System.Text.Encoding.Default.GetBytes("ghi"); int offset = 0; int count = buffer.Length; // Connect to echo port tcp1.Connect("atropos", 7); // Send data until the delimiter is reached. bool found = tcp1.Stream.Write(buffer, delimiter, ref offset, ref count); // Flush the rest of the data tcp1.Stream.Flush(); // Recieve data. string s = tcp1.Stream.Read(); Debug.WriteLine(s); /* Output * ----------------------- * abcdef */ | |
All the read and write methods of SegmentedStream automatically maintain the buffer, so there is no need to invoke Flush when switching back and forth between reading and writing.
Target Platforms: Microsoft .NET Framework 2.0