TCP Client on NUCLEO-F746ZG can't connect to a TCP Server on my PC using Hercules
Hello,
I want to transmit data between two boards using TCP. To do this, one will run a client and the other will run a server. Both of these implementations follow the provided examples. The server works fine, I can connect to it from Hercules and transfer data.
The client implementation is causing me problems, as it can't seem to establish a connection to a TCP server. I can however ping it just fine. Both boards are assigned an IP via DHCP, but the address is always the same and matches with what I expect. Here is the code:
static void tcpecho_client_thread(void const *arg)
{
struct netconn *xNetConn = NULL;
err_t bind_err, connect_err;
char* b_data = "OK"; // Data to be sent
uint16_t b_len = sizeof ( b_data );
IP4_ADDR(&local_ip, IP_ADDR0_CLIENT, IP_ADDR1_CLIENT, IP_ADDR2_CLIENT, IP_ADDR3_CLIENT);
IP4_ADDR(&pc_ip, IP_ADDR0_PC, IP_ADDR0_PC, IP_ADDR2_PC, IP_ADDR3_PC);
xNetConn = netconn_new ( NETCONN_TCP );
if (xNetConn != NULL){
bind_err = netconn_bind ( xNetConn, &local_ip, TCP_PORT_NETCONN );
if(bind_err == ERR_OK){
// Try to connect to server
for(;;){
connect_err = netconn_connect ( xNetConn, &pc_ip, TCP_PORT_NETCONN);
if (connect_err == ERR_OK){
// We are connected
while(1){
BSP_LED_On(LED1);
netconn_write(xNetConn, b_data, b_len, NETCONN_COPY);
vTaskDelay(1000); // To see the result easily in Comm Operator
}
}
}
}else{
// Failed to bind the connection
BSP_LED_On(LED3);
}
}else{
// Failed to allocate a new connection
BSP_LED_On(LED3);
}
}As I can ping it, I don't think something is fundamentally wrong. Is there something I am missing here? In the for loop, it should try to establish a connection until it succeeds, but it never actually manages to connect to something.
