I need to implement a TCP client for a MQTT application with freeRTOS. I need to implement functions that send and receive data over TCP. Unfortunately, the connect() function doesn't work. I am using MPC5748G and lwip for TCP/IP stack.
I tried using bothe the netconn API (netconn_connect), as well as socket API - both of them freeze in sys_arch_sem_wait() on the LWIP_ASSERT("sem != NULL", sem != NULL);
Strangely UDP communication and other TCP functionality is correct: the netconn_listen(), netconn_accept(), and others work fine. Only the netconn_connect() makes the board freeze.
my code:
int TCPClientSendTest(){
struct sockaddr_in client_address;
struct sockaddr_in server_address;
int cfd;
socklen_t client_address_len;
char welcome_msg[] = "\nClient sends a message" ;
if ( (cfd = socket(AF_INET, SOCK_STREAM, 0)) == -1 ) { return -1; }
client_address.sin_addr.s_addr = inet_addr("192.168.140.3");
client_address.sin_family = AF_INET;
client_address.sin_port = htons(SRC_PORT_NUM);
if(bind(cfd, (struct sockaddr *) &client_address, sizeof(client_address))< 0){ return -2; }
server_address.sin_addr.s_addr = inet_addr("192.168.140.2");
server_address.sin_port = htons(DST_PORT_NUM);
server_address.sin_family = AF_INET;
if ( (connect(cfd,(struct sockaddr *) &server_address, sizeof(server_address))) < 0 ) { return -3;} //DOESN'T WORK! BOARD FREEZES
if ((send(cfd, (const char *)welcome_msg, strlen(welcome_msg)+1,0)) < 0){ return -4; }
return 0;
}
Did you ever figure this out? I'm seeing the exact same issue.
Hi, I am facing the same issue. The netconn_connect(); function doesn't show any return value. Do you have any luck?