lwip UDP实验遇到的问题

2019-07-14 19:26发布

我用的是STM32F107VCT6的芯片

u8 *replay = "I got a message! ";

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 图1
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
2条回答
i小方方
1楼-- · 2019-07-15 00:08
 精彩回答 2  元偷偷看……
luopoguixiong
2楼-- · 2019-07-15 03:26
楼主,你好,怎么解决的方便提供一下吗?谢谢

一周热门 更多>