udpecho.c

来自「网络服务器上实现操作系统和嵌入式协议栈的 结合」· C语言 代码 · 共 44 行

C
44
字号
#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);  

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?