天线|RF射频
直播中

李冲备

7年用户 153经验值
私信 关注
[问答]

请问lwip UDP实验出现这两种结果是怎么回事?

我用的是STM32F107VCT6的芯片
u8 *replay = "I got a message!n";
void APP_udp_server_init(void)
{
//创建控制块
if(pAppUdpSvrPCB == NULL)
pAppUdpSvrPcb = udp_new();
  /* Bind the upcb to the UDP_PORT port */
   /* Using IP_ADDR_ANY allow the upcb to be used by any local interface */
   udp_bind(pAppUdpSvrPcb, IP_ADDR_ANY, udplocalport);
   
   /* Set a receive callback for the upcb */
   udp_recv(pAppUdpSvrPcb, APP_udp_callback, replay);     //注册回调函数APP_udp_callback,每当接收到网络调试助手发来的信息就会执行回调函数
}
//回调函数,功能是将I got a message!发回网络调试助手
void APP_udp_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
{
    struct ip_addr destAddr = *addr;
    if(p != NULL)
   {
       /* Tell the client that we have accepted it */
        memset(p->payload,0,p->len);
        memcpy(p->payload,arg,strlen(arg));
        udp_sendto(upcb,p,&destAddr,port);
       /* Free the p buffer */
       pbuf_free(p);
       udp_disconnect(upcb);
   }
}
理想的结果应该是显示I got a message!    然而结果却为I (I和一个空格)。也就是说每次发送都只能显示两个字符
后来我在memset和memcpy中间也加了udp_sendto(upcb,p,&destAddr,port);,结果变成了,先输出一个空格,再输出I got a message!(如图1所示)
请各位大佬给我解释一下,出现这两种结果的原因,拜托了

回帖(1)

周润艺

2019-10-11 09:13:31
已经解决了哈哈,谢谢大***贵的时间
举报

更多回帖

发帖
×
20
完善资料,
赚取积分