Hello,
If you look at KSDK 1.3 examples, you will find the lwip_udpecho_demo_freertos_frdmk64f project that echoes udp data.
In this example, you will notice that netconn_send() function is used to send the data over UDP:
/**
* Send data over a UDP or RAW netconn (that is already connected).
*
* @param conn the UDP or RAW netconn over which to send data
* @param buf a netbuf containing the data to send
* @return ERR_OK if data was sent, any other err_t on error
*/
err_t
netconn_send(struct netconn *conn, struct netbuf *buf)
{
struct api_msg msg;
err_t err;
LWIP_ERROR("netconn_send: invalid conn", (conn != NULL), return ERR_ARG;);
LWIP_DEBUGF(API_LIB_DEBUG, ("netconn_send: sending %"U16_F" bytes\n", buf->p->tot_len));
msg.function = do_send;
msg.msg.conn = conn;
msg.msg.msg.b = buf;
err = TCPIP_APIMSG(&msg);
NETCONN_SET_SAFE_ERR(conn, err);
return err;
}
You only need to use conn pointer as NETCONN_UDP:
static void udpecho_thread(void *arg)
{
static struct netconn *conn;
static struct netbuf *buf;
char buffer[100];
err_t err;
LWIP_UNUSED_ARG(arg);
netif_set_up(&fsl_netif0);
conn = netconn_new(NETCONN_UDP);
LWIP_ASSERT("con != NULL", conn != NULL);
netconn_bind(conn, NULL, 7);
while (1)
{
err = netconn_recv(conn, &buf);
if (err == ERR_OK)
{
if(netbuf_copy(buf, buffer, buf->p->tot_len) != buf->p->tot_len)
{
LWIP_DEBUGF(UDPECHO_DBG, ("netbuf_copy failed\r\n"));
}
else
{
buffer[buf->p->tot_len] = '\0';
err = netconn_send(conn, buf);
if(err != ERR_OK)
{
LWIP_DEBUGF(UDPECHO_DBG, ("netconn_send failed: %d\r\n", (int)err));
}
else
{
LWIP_DEBUGF(UDPECHO_DBG, ("got %s\r\n", buffer));
}
}
netbuf_delete(buf);
}
}
}
You can also look for udpecho_thread to see how connection is established, receiving and sending data over UDP.
I hope this can help you!
Best Reards,
Isaac
----------------------------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
----------------------------------------------------------------------------------------------------------------------------------------