
| Visual Basic (Declaration) | |
|---|---|
<DescriptionAttribute("The Tcp Component integrates event handling, Stream support, and a concise TCP model")> <ToolboxItemAttribute(ToolboxItemType=, ToolboxItemTypeName="")> Public Class Tcp Inherits System.ComponentModel.Component | |
| Visual Basic (Usage) | Copy Code |
|---|---|
Dim instance As Tcp | |
| C# | |
|---|---|
[DescriptionAttribute("The Tcp Component integrates event handling, Stream support, and a concise TCP model")] [ToolboxItemAttribute(ToolboxItemType=, ToolboxItemTypeName="")] public class Tcp : System.ComponentModel.Component | |
| Managed Extensions for C++ | |
|---|---|
[DescriptionAttribute("The Tcp Component integrates event handling, Stream support, and a concise TCP model")] [ToolboxItemAttribute(ToolboxItemType=, ToolboxItemTypeName="")] public __gc class Tcp : public System.ComponentModel.Component | |
| C++/CLI | |
|---|---|
[DescriptionAttribute("The Tcp Component integrates event handling, Stream support, and a concise TCP model")] [ToolboxItemAttribute(ToolboxItemType=, ToolboxItemTypeName="")] public ref class Tcp : public System.ComponentModel.Component | |
| Visual Basic | Copy Code |
|---|---|
Private Sub TcpDemo() ' 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 Echo Server Tcp1.Connect("myEchoServer", 7) ' Send some data Tcp1.Send("Hello Server!" + vbCrLf) ' Get response from the server Dim seg As Segment = Tcp1.Receive() Debug.WriteLine(seg.ToString()) ' Send more data Tcp1.Send("You are a swell host" + vbCrLf) ' Get response from the server seg = Tcp1.Receive() Debug.WriteLine(seg.ToString()) 'Close the connection Tcp1.Close() End Sub | |
| C# | Copy Code |
|---|---|
private void TcpDemo() { // 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 Echo Server tcp1.Connect("myEchoServer", 7); // Send some data tcp1.Send("Hello Server!\r\n"); // Get response from the server Segment seg = tcp1.Receive(); Debug.WriteLine(seg.ToString()); // Send more data tcp1.Send("You are a swell host\r\n"); // Get response from the server seg = tcp1.Receive(); Debug.WriteLine(seg.ToString()); //Close the connection tcp1.Close(); } | |
Use the Tcp Component to establish and manage socket-level streams of data. It simplifies the use of TCP communications by providing methods to establish connections, send and receive data, and terminate connections. Synchronous and asynchronous use is fully supported.
Using the Tcp Component
What follows are short usage descriptions. For more information, see the appropriate member topic.
Low-level interface vs stream interface: Choose between sending data directly over the socket using a low-level interface, or use the stream interface to send/receive data with additional, stream-specific functionality. If you wish to use the low-level interface, you would use the Tcp.Send and Tcp.Receive methods. If you wish to use the stream-interface, use the Tcp.Stream.Read and Tcp.Stream.Write methods.
Connecting: To connect to a host, use either Tcp.Connect (to connect synchronously) or Tcp.BeginConnect (to connect asynchronously), specifying a remote host and port to connect to. Both of these methods are overloaded to allow the specification of a local interface/port as well.
Sending data using the low-level interface: After connecting, send data by using either Tcp.Send (to send data synchronously) or Tcp.BeginSend (to send data asynchronously). These methods are overloaded to allow sending of strings or byte arrays. A Segment object is returned from all Send operations, containing information about the data sent.
Sending data using the stream interface: To send data using the stream interface, use Tcp.Stream.Write. The stream interface offers additional functionality over the low-level interface for sending data such as sending data up to a delimiter and sending data while replacing characters.
Receiving data using the low-level interface: To receive data, use either Tcp.Receive (to receive data synchronously) or Tcp.BeginReceive (to receive data asynchronously). This method is most useful when you either want to receive all available data in the buffer.
Receiving data using the stream-interface: To receive data using the stream interface, use Tcp.Stream.Read. The stream interface offers additional functionality over the low-level interface for receiving data such as receiving up to a delimiter or filling a fixed-size buffer.
Event notification: The Tcp component provides full event support including the Tcp.Trace event, raised when data is sent or received, the Tcp.ConnectedChanged event, raised when the value of Tcp.Connected changes.
Socket option configuration: The Tcp component enables socket option configuration (such as KeepAlive and NoDelay socket options, for example) by simply setting properties of the Tcp component. In addition, buffer-size/socket timeout configuration is possible by setting both the sending or receiving buffer size, and the sending and receiving timeout value.
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
Dart.PowerTCP.Mail.Tcp
Target Platforms: Microsoft .NET Framework 2.0