www.pudn.com > uCOS_II_uart.rar > udpecho.c


#include "lwip/api.h"
#include "lwip/sys.h"

/*-----------------------------------------------------------------------------------*/
void 
udpecho_thread(void *arg)
{
struct netconn *conn;
struct netbuf *buf;
struct ip_addr addr;

char text[] = "This is a Test UDP packet.";

/* create a new connection */
conn = netconn_new(NETCONN_UDP);

/* set up the IP address of the remote host */
addr.addr = htonl(0xc0a80063);

/* connect the connection to the remote host */
netconn_connect(conn, &addr, 7000);

/* reference the text into the netbuf */
netbuf_ref(buf, text, sizeof(text));

while(1)
{
/* send the text */
netconn_send(conn, buf);

}
/* deallocate connection and netbuf */
netconn_delete(conn);
netbuf_delete(buf);

}
/*-----------------------------------------------------------------------------------*/
void
udpecho_init(void)
{
  sys_thread_new(udpecho_thread, NULL,TCPIP_THREAD_PRIO);  

}