www.beck-ipc.com

@CHIP-RTOS C Library V2.00 - TCP/IP API


connect

Connect to another socket.

int connect ( int sd,
              const struct sockaddr_in far *addressPtr, int *error );

Parameters

sd

Socket descriptor.

addressPtr

Pointer to a sockaddr_in structure containing host's IP address and port number.

error

Output parameter:  Failure code, 0 on success.

Return Value

0 = success
Non-zero = Failure (see error output parameter)

Comments

The caller must fill in the sockaddr_in data structure at addressPtr prior to calling here.   An example of how this normally would be done follows.   The PF_INET setting for the sin_family is required.

// Example
char szHostIPStr[] = "172.30.1.68" ;
int HostPort = 3000 ;
struct sockaddr_in addr ;
int error_code ;

addr.sin_family = PF_INET ;
addr.sin_addr.s_addr =  0 ;
addr.sin_port = htons (HostPort) ;   // convert byte order

// convert server IP address string to binary
inet_addr (szHostIPStr, &addr.sin_addr.s_addr);
// establish a connection to the server
error_code = connect (sd, &addr) ;

See Also

RTOS API

This library function invokes a RTOS software interrupt. Refer to this RTOS API function's documentation for more details.


This API List
List of C Libraries
@CHIP-RTOS Main Index


End of document