System.Net.Socket.TSocket.Connect

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure Connect(const Name, Address, Service: string; Port: Word); overload;
procedure Connect(const EndPoint: TNetEndpoint); overload;

C++

void __fastcall Connect(const System::UnicodeString Name, const System::UnicodeString Address, const System::UnicodeString Service, System::Word Port)/* overload */;
void __fastcall Connect(const TNetEndpoint &EndPoint)/* overload */;

Properties

Type Visibility Source Unit Parent
procedure
function
public
System.Net.Socket.pas
System.Net.Socket.hpp
System.Net.Socket TSocket

Description

Establishes a connection to the specified endpoint.

In order to establish a direct connection, the type of your socket must be RAW, RDM, SEQ, or TCP. If the type of your socket is UDP, Connect attempts to bind your socket to the specified address instead of establishing a connection to that address.

To specify the target endpoint, you must provide any of the following combinations of parameters:

  • An endpoint (Endpoint).
  • An IP address (Address) and a service (Service). You may pass an empty word as Port, as Service is used to determine the port.
  • An IP address (Address) and a port (Port). Pass an empty string as Service. Otherwise the specified service name is used to determine the port to use, and the specified port is ignored.

Exceptions

A call to Connect can raise any of the following exceptions:

Exception Exception.Message Scenarios

ESocketError

Network socket error: <error message> (<error code>), on API 'bind'

Network socket error: <error message> (<error code>), on API 'connect'

Network socket error: <error message> (<error code>), on API 'socket'

No address specified

  • You did not specify enough information to determine the address of the socket. Connect raises this exception when both Name and Address are empty strings.

Socket already open

See Also