1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
27
28
29
30
38
39
40
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
66
67
68
69
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* ... */
#include "main.h"
#include "lwip/pbuf.h"
#include "lwip/udp.h"
#include "lwip/tcp.h"
#include <string.h>
#include <stdio.h>
6 includes
Includes
void udp_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port);
u8_t data[100];
__IO uint32_t message_count = 0;
struct udp_pcb *upcb;
Private function prototypes
/* ... */
void udp_echoclient_connect(void)
{
ip_addr_t DestIPaddr;
err_t err;
upcb = udp_new();
if (upcb!=NULL)
{
IP4_ADDR( &DestIPaddr, DEST_IP_ADDR0, DEST_IP_ADDR1, DEST_IP_ADDR2, DEST_IP_ADDR3 );
err= udp_connect(upcb, &DestIPaddr, UDP_SERVER_PORT);
if (err == ERR_OK)
{
udp_recv(upcb, udp_receive_callback, NULL);
}if (err == ERR_OK) { ... }
}if (upcb!=NULL) { ... }
}{ ... }
/* ... */
void udp_echoclient_send(void)
{
struct pbuf *p;
sprintf((char*)data, "sending udp client message %d", (int)message_count);
p = pbuf_alloc(PBUF_TRANSPORT,strlen((char*)data), PBUF_POOL);
if (p != NULL)
{
pbuf_take(p, (char*)data, strlen((char*)data));
udp_send(upcb, p);
pbuf_free(p);
}if (p != NULL) { ... }
}{ ... }
/* ... */
void udp_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
{
message_count++;
pbuf_free(p);
}{ ... }