Export (0) Print
Expand All

TcpClient.Connect Method

Connects the client to a remote TCP host using the specified host name and port number.

Overload List

Connects the client to a remote TCP host using the specified remote network endpoint.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub Connect(IPEndPoint)
[C#] public void Connect(IPEndPoint);
[C++] public: void Connect(IPEndPoint*);
[JScript] public function Connect(IPEndPoint);

Connects the client to a remote TCP host using the specified IP address and port number.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub Connect(IPAddress, Integer)
[C#] public void Connect(IPAddress, int);
[C++] public: void Connect(IPAddress*, int);
[JScript] public function Connect(IPAddress, int);

Connects the client to the specified port on the specified host.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub Connect(String, Integer)
[C#] public void Connect(string, int);
[C++] public: void Connect(String*, int);
[JScript] public function Connect(String, int);

Example

[Visual Basic, C#, C++] The following example uses the host name and port number to connect with a remote host.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Connect. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
'Uses a host name and port number to establish a socket connection.
Dim tcpClient As New TcpClient()

   tcpClient.Connect("www.contoso.com", 11002)


[C#] 
//Uses a host name and port number to establish a socket connection.
TcpClient tcpClient = new TcpClient ();
tcpClient.Connect ("www.contoso.com", 11002);


[C++] 
//Uses a host name and port number to establish a socket connection.
 TcpClient* tcpClient = new TcpClient();
 tcpClient->Connect(S"www.contoso.com", 11002);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

TcpClient Class | TcpClient Members | System.Net.Sockets Namespace

Show:
© 2014 Microsoft