Dart.PowerTCP.SslSockets Namespace > Tcp Class > Connect Method : Connect(String,String) Method |
Connect to a host.
[Visual Basic]
<DescriptionAttribute("Connect to a server.")>
Overloads Public Sub Connect( _
ByVal server As String, _
ByVal serverPort As String _
)
[C#]
[DescriptionAttribute("Connect to a server.")]
public void Connect(
string server,
string serverPort
);
[C++]
[DescriptionAttribute("Connect to a server.")]
public: void Connect(
string* server,
string* serverPort
)
[C++/CLI]
[DescriptionAttribute("Connect to a server.")]
public:
void Connect(
String^ server,
String^ serverPort
)
The 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 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.
The following example demonstrates connecting to an echo port, sending data, receiving data, then closing the connection.
[Visual Basic]
Private Sub TcpDemo()
' Connect to echo port.
Tcp1.Connect("atropos", "7")
' Send some data
Dim seg As Segment = Tcp1.Send("Hello")
' Display info
Debug.WriteLine("Bytes of data sent: " & seg.Count)
Debug.WriteLine("Data sent: " & seg.ToString())
' Receive response (this should be the same as the sent data)
seg = Tcp1.Receive()
' Display info
Debug.WriteLine("Bytes of data received: " & seg.Count)
Debug.WriteLine("Data received: " & seg.ToString())
' Since connection is to an echo port, the client has to
' close the connection.
Try
Tcp1.Close()
Catch ex As Exception
' Error, just dispose the object.
Tcp1.Dispose()
End Try
'* Output
'* --------------------------
'* Bytes of data sent: 5
'* Data sent: Hello
'* Bytes of data received: 5
'* Data received: Hello
'*
End Sub
[C#]
private void TcpDemo()
{
// Connect to echo port.
tcp1.Connect("atropos", "7");
// Send some data
Segment seg = tcp1.Send("Hello");
// Display info
Debug.WriteLine("Bytes of data sent: " + seg.Count);
Debug.WriteLine("Data sent: " + seg.ToString());
// Receive response (this should be the same as the sent data)
seg = tcp1.Receive();
// Display info
Debug.WriteLine("Bytes of data received: " + seg.Count);
Debug.WriteLine("Data received: " + seg.ToString());
// Since connection is to an echo port, the client has to
// close the connection.
try
{
tcp1.Close();
}
catch(Exception ex)
{
// Error, just dispose the object.
tcp1.Dispose();
}
/* Output
* --------------------------
* Bytes of data sent: 5
* Data sent: Hello
* Bytes of data received: 5
* Data received: Hello
*/
}
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Tcp Class | Tcp Members | Overload List
Send comments on this topic.
Documentation version 1.1.2.0.
© 2008 Dart Communications. All rights reserved.