MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / udpecho_entry

Function udpecho_entry

examples/test/net_test.c:24–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22#define UDP_ECHO_PORT 7
23rt_thread_t udpecho_tid = RT_NULL;
24void udpecho_entry(void *parameter)
25{
26 struct netconn *conn;
27 struct netbuf *buf;
28 struct ip_addr *addr;
29 unsigned short port;
30
31 conn = netconn_new(NETCONN_UDP);
32 if(conn == NULL)
33 {
34 rt_kprintf("no memory error\n");
35 return;
36 }
37 netconn_bind(conn, IP_ADDR_ANY, 7);
38
39 while(1)
40 {
41 /* received data to buffer */
42#if LWIP_VERSION_MINOR==3U
43 buf = netconn_recv(conn);
44#else
45 netconn_recv(conn, &buf);
46#endif
47 if(buf == NULL)
48 {
49 break;
50 }
51 addr = netbuf_fromaddr(buf);
52 port = netbuf_fromport(buf);
53
54 /* send the data to buffer */
55 netconn_connect(conn, addr, port);
56
57 /* reset address, and send to client */
58#if LWIP_VERSION_MINOR==3U
59 buf->addr = RT_NULL;
60#else
61 buf->addr = *IP_ADDR_ANY;
62#endif
63
64 netconn_send(conn, buf);
65
66 /* release buffer */
67 netbuf_delete(buf);
68 }
69
70 netconn_delete(conn);
71}
72/*
73 * UDP socket echo server
74 */

Callers

nothing calls this directly

Calls 7

rt_kprintfFunction · 0.85
netconn_bindFunction · 0.50
netconn_recvFunction · 0.50
netconn_connectFunction · 0.50
netconn_sendFunction · 0.50
netbuf_deleteFunction · 0.50
netconn_deleteFunction · 0.50

Tested by

no test coverage detected