@CHIP-RTOS C Library V2.06 - TCP/IP API
tcp_connect
Open a client TCP/IP socket connection to a specified
host. int tcp_connect ( const char far *DestIPStr,
unsigned int ClientPort,
unsigned int HostPort,
int *error ); Parameters
DestIPStr
- Pointer to server's IPv4 address,
expressed as a null terminated ASCII string in network dot notation.
ClientPort
- Optional local port number to assign to socket.
Set this to zero if a bind operation is not desired (random port).
HostPort
- Remote port number to which connection is desired.
error
- Output parameter: Failure
code, 0 on success.
Return Value
- -1 = Failure (see error
output parameter)
else new socket descriptor
Comments
- This function calls the required set of TCP/IP functions
to establish a IPv4 client connection to a host.
Pseudo code:
struct sockaddr_in addr;
int sd = opensocket(SOCK_STREAM, error) ;
addr.sin_family = PF_INET ;
addr.sin_addr.s_addr = 0 ;
IF ClientPort != 0 THEN
addr.sin_port = htons(ClientPort) ;
bind(sd, &addr, error) ;
ENDIF
addr.sin_port = htons(HostPort) ;
error = inet_addr(DestIPStr, &addr.sin_addr.s_addr) ;
error = connect (sd, (const struct sockaddr *)&addr) ;
return sd ;
The error handling is not shown in the above simplified pseudo code.
In case of errors, the socket is closed by this API function and a return
is made from the point of the error with return value -1.
On success, the new socket descriptor is returned. The caller is then
responsible for calling closesocket when
finished with the connection.
SC1x3 Comments- The actual library function reached
here is named tcp_connect_ipstackV2
. The name change
occurs due to a macro in the library header file.
See Also
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 |
-
V1.00 | V1.00 | V1.00 | V0.90 |
This API List
List of C Libraries
@CHIP-RTOS Main Index
End of document
|