NetXDuo TCP Client Notify Issue
Hi all,
I am currently running tcp echo client example code from st on a NUCLEO-H563ZI which I have got working send and receiving messages over TCP/IP I am trying to get nx_tcp_socket_receive_notify working however when I use the function and connect to the server the callback is never called when the server sends a message any ideas why its not would be great I have attached the code to give a better idea of what I am doing.
volatile int data_received_flag = 0;
static VOID App_TCP_Thread_Entry(ULONG thread_input){
UINT ret;
UINT count = 0;
ULONG bytes_read;
UCHAR data_buffer[512];
ULONG source_ip_address;
UINT source_port;
NX_PACKET *server_packet;
NX_PACKET *data_packet;
/* create the TCP socket */
ret = nx_tcp_socket_create(&NetXDuoEthIpInstance, &TCPSocket, "TCP Server Socket", NX_IP_NORMAL, NX_FRAGMENT_OKAY,
NX_IP_TIME_TO_LIVE, WINDOW_SIZE, NX_NULL, NX_NULL);
if (ret != NX_SUCCESS){
Error_Handler();
}
/* bind the client socket for the DEFAULT_PORT */
ret = nx_tcp_client_socket_bind(&TCPSocket, DEFAULT_PORT, NX_WAIT_FOREVER);
if (ret != NX_SUCCESS){
Error_Handler();
}
/* connect to the remote server on the specified port */
//ret = nx_tcp_client_socket_connect(&TCPSocket, host_ip_address, TCP_SERVER_PORT, NX_WAIT_FOREVER);
ret = nx_tcp_client_socket_connect(&TCPSocket, TCP_SERVER_ADDRESS, TCP_SERVER_PORT, NX_WAIT_FOREVER);
if (ret != NX_SUCCESS){
//Error_Handler();
uartOut("Can't connect to server", true);
}else{
uartOut("Connected to server", true);
}
// Register the callback
ret = nx_tcp_socket_receive_notify(&TCPSocket, tcp_data_received_callback);
if (ret != NX_SUCCESS){
//Error_Handler();
uartOut("Can't setup notify", true);
}else{
uartOut("Can setup notify", true);
}
while (1)
{
//uartOut("waiting on messaage", true);
// Main application loop
if (data_received_flag)
{
char receive_buffer[512];
// Receive data when the flag is set
ret = nx_tcp_socket_receive(&TCPSocket, &server_packet,NX_APP_DEFAULT_TIMEOUT);
// Process the received data as needed
// Clear the flag
data_received_flag = 0;
if (ret == NX_SUCCESS) {
/* get the server IP address and port */
nx_udp_source_extract(server_packet, &source_ip_address, &source_port);
/* retrieve the data sent by the server */
nx_packet_data_retrieve(server_packet, data_buffer, &bytes_read);
/* print the received data */
PRINT_DATA(source_ip_address, source_port, data_buffer);
/* release the server packet */
nx_packet_release(server_packet);
uartOut(" Server: ", false);
uartOut(data_buffer, true);
/* toggle the green led on success */
HAL_GPIO_WritePin(GPIOI, GPIO_PIN_9, GPIO_PIN_SET);
} else {
/* no message received exit the loop */
// break;
uartOut(" Issue getting data back from server", true);
}
}
// Your main application logic goes here
}
}
VOID tcp_data_received_callback(NX_TCP_SOCKET * p_socket) {
// This callback is called when data is received on the TCP socket.
data_received_flag = 1;
}
