PowerTCP Sockets for .NET
Tcp Class
Members  Example 




The Tcp component simplifies the use of secure Tcp communications within any .NET application.
Object Model
Tcp ClassTcpSocketOption Class
Syntax
'Declaration
 
Public Class Tcp 
   Inherits PtyBase
'Usage
 
Dim instance As Tcp
public class Tcp : PtyBase 
public __gc class Tcp : public PtyBase 
public ref class Tcp : public PtyBase 
Remarks

The Tcp component establishes and manages TCP-level streams of data. Methods for establishing connections, and sending and receiving data simplify Tcp communications for the user, while still providing options for advanced customization. Secure SSL connections and worker thread operation are fully supported.

The Tcp component can optionally be bound to a display control for easy user-interactive development.

Using the Tcp Component

The Tcp component's clean interface provides clear, straight-forward use. All methods calls are blocking calls, making programming an intuitive step-by-step process. Functions can be passed to the Start method, to execute on worker threads without blocking the user interface. Marshaling data from these worker threads is made convenient using the overloaded Marshal methods. See the Asynchronous Operation page for more information on this topic.

Binding the Tcp Component to a Display

Set the Pty (pseudo terminal) property to bind the Telnet component to a display control derived from TextBoxBase (such as a standard TextBox), and call Connect to establish a connection to the specified host. Once connected, keystrokes will be sent automatically, and data received will appear in the text area.

Example
The following example demonstrates simple Tcp read and write operations on a worker thread, and marshaling the received data to the main thread.
private void button1_Click(object sender, EventArgs e)
{
    tcp1.Start(connectWriteRead, null);
}

private void connectWriteRead(object state)
{
    tcp1.Connect(new TcpSession(new Dart.Sockets.IPEndPoint(myEchoServer, 7)));
    tcp1.Write("hello world!");
    byte[] buffer = new byte[128];
    tcp1.Marshal(tcp1.Read(buffer), "", null);
    tcp1.Close();
}

void tcp1_Data(object sender, Dart.Sockets.DataEventArgs e)
{
    textBox1.AppendText(e.Data.ToString());
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    tcp1.Start(AddressOf connectWriteRead, Nothing)
End Sub

Private Sub connectWriteRead(ByVal state As Object)
    tcp1.Connect(New TcpSession(New Dart.Sockets.IPEndPoint(myEchoServer, 7)))
    tcp1.Write("hello world!")
    Dim buffer(127) As Byte
    tcp1.Marshal(tcp1.Read(buffer), "", Nothing)
    tcp1.Close()
End Sub

Private Sub tcp1_Data(ByVal sender As Object, ByVal e As Dart.Sockets.DataEventArgs)
    textBox1.AppendText(e.Data.ToString())
End Sub
Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         Dart.Sockets.ComponentBase
            Dart.Sockets.SocketBase
               Dart.Sockets.TcpBase
                  Dart.Sockets.PtyBase
                     Dart.Sockets.Tcp

See Also

Reference

Tcp Members
Dart.Sockets Namespace


PowerTCP Sockets for .NET Documentation Version 4.5
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic