PowerTCP Mail for .NET
Connect(String,Int32) Method
See Also  Example Send comments on this topic.
Dart.PowerTCP.Mail Namespace > Tcp Class > Connect Method : Connect(String,Int32) Method




server
Remote hostname or address in dot notation.
serverPort
Remote port, a number between 1 and 65535, inclusive.
Connect to a host.

Syntax

Visual Basic (Declaration) 
<DescriptionAttribute("Connect to a server.")>
Public Overloads Sub Connect( _
   ByVal server As String, _
   ByVal serverPort As Integer _
) 
Visual Basic (Usage)Copy Code
Dim instance As Tcp
Dim server As String
Dim serverPort As Integer
 
instance.Connect(server, serverPort)
C# 
[DescriptionAttribute("Connect to a server.")]
public void Connect( 
   string server,
   int serverPort
)
Managed Extensions for C++ 
[DescriptionAttribute("Connect to a server.")]
public: void Connect( 
   string* server,
   int serverPort
) 
C++/CLI 
[DescriptionAttribute("Connect to a server.")]
public:
void Connect( 
   String^ server,
   int serverPort
) 

Parameters

server
Remote hostname or address in dot notation.
serverPort
Remote port, a number between 1 and 65535, inclusive.

Example

The following example demonstrates blocking operations using the Tcp component.
Visual BasicCopy 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();
}

Remarks

The Tcp.Connect method establishes a network connection between the default local network interface/port and the device identified by remote network address/port. If no exception is thrown, the connection has succeeded and the Tcp.Connected property will return true after this method returns. Once the connection has been made, you can send/receive data to/from the server.

This method always blocks until the attempted connection succeeds or fails.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.