XDK API  3.6.0
Documentation
Functions
Serval_XTcpClient.h File Reference

The interface description of a proprietary TCP Client based application protocol. More...

#include <Serval_Defines.h>
#include <Serval_Types.h>
#include <PIp.h>
#include <Serval_Msg.h>
#include <Serval_XTcp.h>
+ Include dependency graph for Serval_XTcpClient.h:

Functions

retcode_t XTcpClient_connect (const Ip_Address_T serverIp, Ip_Port_T serverPort, AppXTcpCallback_T appSndCallback, AppXTcpCallback_T appRcvCallback)
 Initiate a client side, generic TCP connection with a server. Note that the connection is not opened immediately after this function has returned, since the three-way TCP handshake needs to complete first. It is still possible to use the connection for transmitting data, but there might be an additional, initial delay. More...
 
retcode_t XTcpClient_initialize (void)
 Initialize the XTCP client including all needed modules. More...
 

Detailed Description

Since
1.4

Function Documentation

retcode_t XTcpClient_connect ( const Ip_Address_T  serverIp,
Ip_Port_T  serverPort,
AppXTcpCallback_T  appSndCallback,
AppXTcpCallback_T  appRcvCallback 
)
Parameters
[in]serverIpIp address of the server to connect to.
[in]serverPortThe port which is used to send and receive messages. It has to be a valid port number (!=0).
[in]appSndCallbackCallback function invoked when a) data is received in which case the status passed is RC_OK b) the connection has been closed in which case RC_XTCP_CONNECTION_CLOSED is passed c) the payload sent by XTcp_push has been sent in which case RC_XTCP_SENT is passed d) an error has occurred in which case the error code is passed to the callback. Most notably, a RC_XTCP_CONNECTION_FAILED error code is passed to the callback if the connection attempt has timed out.
[in]appRcvCallbackCallback function invoked when a) data is sent in which case the status passed is RC_OK b) the connection has been closed in which case RC_XTCP_CONNECTION_CLOSED is passed c) the payload sent by XTcp_push has been sent in which case RC_XTCP_SENT is passed d) an error has occurred in which case the error code is passed to the callback. Most notably, a RC_XTCP_CONNECTION_FAILED error code is passed to the callback if the connection attempt has timed out.
Return values
RC_OKon success or
RC_XTCP_SOCKET_ERRORif opening the TCP socket fails.
Example
Start a Tcp Client
1 retcode_t rc;
2 uint16_t serverPort = 9999;
3 const char * serverIp = "192.168.0.101";
4 Ip_Address_T destAddress;
5 
6 // Change Port format from host to network. Needed for xTCP module
7 Ip_Port_T destPort = Ip_convertIntToPort(serverPort);
8 
9 // Convert IP address format
10 Ip_convertStringToAddr(serverIp, &destAddress);
11 destAddress = Basics_htonl(destAddress);
12 
13 rc = XTcpClient_connect(destAddress, destPort, appSendCallback, appReceiveCallback);
14 if (RC_OK == rc)
15 {
16  printf("TCP Client Starting. Trying connecting to %s:%d\r\n", serverIp, serverPort);
17 }
18 else
19 {
20  printf("TCP Client not started; RC = %i\r\n", rc);
21 }
See also
XTcpServer_listen()
retcode_t XTcpClient_initialize ( void  )
Return values
RC_OKon successful
RC_XTCP_CLIENT_INIT_ERRORif an error occurs while initializing the XTcp Client
Example
Initialize a XTcp Client
1 // Initialize a TCP Client
2 if (RC_OK != XTcpClient_initialize())
3 {
4  printf("Util and xTCP initialization failure!\n\r");
5 }

All rights reserved. The use is subject to the XDK SDK EULA by Bosch Connected Devices and Solutions GmbH.
This documentation file has been automatically generated on Thu Mar 14 2019 19:12:46 by doxygen 1.8.8