Home |
Function connect |
Function connectEstablishes a connection to a remote host. int connect(SOCKET socket, const struct sockaddr * addr, int addrlen); ParameterssocketSocket returned by socket. addrAddress of the target to connect to; port number (TCP and UDP) and IP address are in network byte order. This parameter has type struct sockaddr * for historical reasons. Use type struct sockaddr_in * instead. addrlenLength of valid information in addr. return valueReturns 0 for UDP. For TCP, 0 if the connection was successfully established, otherwise SOCKET_ERROR. If an error occurred, call xn_getlasterror and xn_geterror_string to return the error value. Section Error Codes further describes each error. Possible values for this function are:
Function connect establishes a connection between a socket and the service provider at the IP address and port number provided in the arguments. If the socket is unbound, connect will bind it implicitly with a unique port number and the local connecting IP address for the interface. For TCP sockets, connect initiates the handshake. If the socket is in blocking mode (see ioctlsocket), connect blocks on the write signal until the connection is established or an error occurs. If the socket is in non-blocking mode (see ioctlsocket), connect returns the error EINPROGRESS after initiating the handshake. select can be called after connect to block (with a timeout) until the connection becomes established. For UDP sockets, the IP address and port number are bound to the socket and the function returns immediately. For RAW sockets, the IP address is bound to the socket and the function returns immediately. The port number is ignored. In order to send to broadcast or multicast addresses, use sendto or connect with remote address set to the broadcast address (INADDR_BROADCAST) or to the multicast address respectfully. In blocking mode, this function blocks infinitely. Use select for a timeout capability. This function does not support sockets in secure mode. For secure sockets, use function net_connect instead.
|