void send_data(void)
{
struct pbuf *q = NULL;
const char* reply = "I'm here ! Are you There ? \n";
struct udp_pcb *upcb;
struct ip_addr addr;
IP4_ADDR(&addr, 192,168,0,125);
upcb = udp_new();
udp_bind(upcb, IP_ADDR_ANY, UDP_ECHO_PORT);
q = pbuf_alloc(PBUF_TRANSPORT, strlen(reply)+1, PBUF_RAM);
if(!q)
{
printf("out of PBUF_RAM\n");
return;
}
memset(q->payload, 0 , q->len);
memcpy(q->payload, reply, strlen(reply));
udp_sendto(upcb, q, &addr, 8080);
pbuf_free(q);
}
在需要的地方调用该函数就可以向IP为192.168.0.125的8080端口发数据 I'm here ! Are you There ? 可以根据自己的需要进行修改。