Here is my client code:
static void prvSimpleClientTask( void *pvParameters )
{
#if (INFOINSHARK == 1)
Socket_t xSharkWinSocket;
struct freertos_sockaddr xSharkWinAddress;
#endif
Socket_t xThisClientSocket, xThatServerSocket;
struct freertos_sockaddr xThisClientSocketAddress,
xThatServerSocketAddress;
static const TickType_t xTxTimeOut = pdMS_TO_TICKS( 2000 );
static const TickType_t xRxTimeOut = pdMS_TO_TICKS( 4000 );
#if( ipconfigUSE_TCP_WIN == 1 )
WinProperties_t xWinProps;
xWinProps.lTxBufSize = 6 * ipconfigTCP_MSS;;
xWinProps.lTxWinSize = 3;
xWinProps.lRxBufSize = 6 * ipconfigTCP_MSS;
xWinProps.lRxWinSize = 3;
#endif /* ipconfigUSE_TCP_WIN */
uint32_t ulCount = 0UL;
volatile static int32_t status, xAlreadyTransmitted,
xTotalLengthToSend, xLenToSend, xBytesSent;
memset( &xThatServerSocketAddress, 0, sizeof(xThatServerSocketAddress) );
xThatServerSocketAddress.sin_address = (IP_Address_t)FreeRTOS_inet_addr( "192.168.0.2" );
xThatServerSocketAddress.sin_family = FREERTOS_AF_INET4;
xThatServerSocketAddress.sin_port = FreeRTOS_htons( 10000 );
#if (INFOINSHARK == 1)
xSharkWinSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP);
configASSERT( xSharkWinSocket != FREERTOS_INVALID_SOCKET );
memset( &xSharkWinAddress, 0, sizeof(xSharkWinAddress) );
xSharkWinAddress.sin_address.ulIP_IPv4 = FreeRTOS_inet_addr( "192.168.0.3" );
xSharkWinAddress.sin_family = FREERTOS_AF_INET4;
xSharkWinAddress.sin_port = FreeRTOS_htons( 10000 );
#endif
for( ;; )
{
xThisClientSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
configASSERT( xThisClientSocket != FREERTOS_INVALID_SOCKET );
FreeRTOS_setsockopt( xThisClientSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) );
FreeRTOS_setsockopt( xThisClientSocket, 0, FREERTOS_SO_RCVTIMEO, &xRxTimeOut, sizeof( xRxTimeOut ) );
FreeRTOS_setsockopt( xThisClientSocket, 0, FREERTOS_SO_SNDTIMEO, &xTxTimeOut, sizeof( xTxTimeOut ) );
FreeRTOS_bind( xThisClientSocket, NULL, sizeof(xThisClientSocketAddress));
#if (INFOINSHARK == 1)
strcpy( WinInfoString, "FreeRTOS_bind");
FreeRTOS_sendto(xSharkWinSocket, WinInfoString, strlen (WinInfoString), 0, &xSharkWinAddress, sizeof(xSharkWinAddress));
#endif
status = FreeRTOS_connect( xThisClientSocket, &xThatServerSocketAddress, sizeof( xThatServerSocketAddress ) );
#if (INFOINSHARK == 1)
if (status == 0)
{
while(1){
strcpy( WinInfoString, "!!!!!!!!!!!!!!!!!!! FreeRTOS_connect == 0 !!!!!!!!!!!");
FreeRTOS_sendto(xSharkWinSocket, WinInfoString, strlen (WinInfoString), 0, &xSharkWinAddress, sizeof(xSharkWinAddress));
}
}
else
{
sprintf( WinInfoString, "%d = FreeRTOS_connect", status);
FreeRTOS_sendto(xSharkWinSocket, WinInfoString, strlen (WinInfoString), 0, &xSharkWinAddress, sizeof(xSharkWinAddress));
}
#endif
vTaskDelay( pdTICKS_TO_MS( 100 ) );
FreeRTOS_closesocket( xThisClientSocket );
#if (INFOINSHARK == 1)
strcpy( WinInfoString, "FreeRTOS_closesocket");
FreeRTOS_sendto(xSharkWinSocket, WinInfoString, strlen (WinInfoString), 0, &xSharkWinAddress, sizeof(xSharkWinAddress));
#endif
vTaskDelay( pdTICKS_TO_MS( 1000 ) );
}
}
Maybe someone will immediately understand what the error is?
If the FreeRTOS_connect function returns a value of 0, a connection will be established, and it returns -128.