Dart.PowerTCP.EmailValidation Namespace > SegmentEventArgs Class : Segment Property (SegmentEventArgs) |
The Segment object referencing the data that was sent or received.
[Visual Basic]
Public ReadOnly Property Segment As Segment
[C#]
public Segment Segment {get;}
[C++]
public: __property Segment* get_Segment();
A Segment object referencing the data that was sent or received.
The Segment object will contain data describing the data that was sent or received. For example, the Segment object will contain the data itself, the amount of bytes sent,' and whether the Segment object was created as a result of data being sent or received.
To access the data contained within the Segment object, simply access the properties of the Segment object. As a shortcut, you can simply get all data contained within the Segment object by using the Segment.ToString method.
The following example demonstrates asynchronous receiving and sending of data.
[Visual Basic]
Private Sub AsynchTcpDemo()
' Attempt to connect to an echo port.
Try
Tcp1.Connect("myserver", 7)
Catch ex As Exception
Return
End Try
' Send data, since we are connected to an echo port, the same data should be returned.
' The following code demonstrates asynchronously sending data. When data has been sent
' the EndSend event will be raised.
Dim buffer() As Byte = System.Text.Encoding.Default.GetBytes("a")
Tcp1.BeginSend(buffer, 0, buffer.Length, Net.Sockets.SocketFlags.None, Nothing)
End Sub
Private Sub Tcp1_EndSend(ByVal sender As Object, ByVal e As Dart.PowerTCP.SegmentEventArgs) Handles Tcp1.EndSend
' Check for exception
If e.Exception Is Nothing Then
' Send is complete. Display info about the data sent.
Debug.WriteLine("Byte count sent: " + e.Segment.Count)
Debug.WriteLine("Data sent: " + e.Segment.ToString())
Dim buffer(Tcp1.ReceiveBufferSize) As Byte
' Receive the data. The EndReceive event will be raised upon completion.
Tcp1.BeginReceive(buffer, 0, buffer.Length, Net.Sockets.SocketFlags.None, Nothing)
End If
End Sub
Private Sub Tcp1_EndReceive(ByVal sender As Object, ByVal e As Dart.PowerTCP.SegmentEventArgs) Handles Tcp1.EndReceive
' Check for exception
If e.Exception Is Nothing Then
' Receive is complete. Display info about the data sent.
Debug.WriteLine("Byte count received: " + e.Segment.Count)
Debug.WriteLine("Data received: " + e.Segment.ToString())
' Close the connection
Tcp1.Close()
End If
End Sub
[C#]
private void AsynchTcpDemo()
{
// Attempt to connect to an echo port.
try
{
tcp1.Connect("myserver", 7);
}
catch(Exception ex)
{return;}
// Send data, since we are connected to an echo port, the same data should be returned.
// The following code demonstrates asynchronously sending data. When data has been sent
// the EndSend event will be raised.
byte[] buffer = System.Text.Encoding.Default.GetBytes("a");
tcp1.BeginSend(buffer, 0, buffer.Length, System.Net.Sockets.SocketFlags.None, null);
}
private void tcp1_EndSend(object
sender, Dart.PowerTCP.SegmentEventArgs e)
{
// Check for exception
if(e.Exception == null)
{
// Send is complete. Display info about the data sent.
Debug.WriteLine("Byte count sent: " + e.Segment.Count);
Debug.WriteLine("Data sent: " + e.Segment.ToString());
byte[] buffer = new
byte[tcp1.ReceiveBufferSize];
// Receive the data. The EndReceive event will be raised upon completion.
tcp1.BeginReceive(buffer, 0, buffer.Length, System.Net.Sockets.SocketFlags.None,
null);
}
}
private void tcp1_EndReceive(object
sender, Dart.PowerTCP.SegmentEventArgs e)
{
// Check for exception
if(e.Exception == null)
{
// Receive is complete. Display info about the data sent.
Debug.WriteLine("Byte count received: " + e.Segment.Count);
Debug.WriteLine("Data received: " +
e.Segment.ToString());
// Close the connection
tcp1.Close();
}
}
Platforms: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP, Windows Server 2003, Windows Vista
SegmentEventArgs Class | SegmentEventArgs Members
Send comments on this topic.
Documentation version 1.0.3.0.
© 2008 Dart Communications. All rights reserved.