各位大神好,
我是stm32初学者,目前我代码运行的有TCP的客户端和client,另外我又加入了udp广播,结果发现当我发送udp广播后,板子就ping不通了,tcp服务端也连不上,但是广播数据还是在发送,我的udp广播代码如下
- void UDP_Broadcast_Send_IP(void)
- {
- struct netbuf *buf_send;
- unsigned short payload_len=0;
- unsigned char *index=NULL;
- unsigned char send_buff[23],pos=0;
- struct netconn *bc_clientconn;
- err_t ret=0;
- bc_clientconn = netconn_new(NETCONN_UDP);
- if(bc_clientconn==NULL)
- return;
- ret=netconn_bind(bc_clientconn,IP_ADDR_ANY,11008);
- /* Prepare data */
- buf_send = netbuf_new();
- send_buff[pos++]=0xFE;
- send_buff[pos++]=0xEF;
- #if LWIP_DHCP//Åжϵ±Ç°ÊÇ·ñΪ×Ô¶¯»ñÈ¡IP
- send_buff[pos++]=0;
- #else
- send_buff[pos++]=1;
- #endif
-
- //IPµØÖ·
- send_buff[pos++]=(unsigned char)(DP83848_netif.ip_addr.addr);
- send_buff[pos++]=(unsigned char)(DP83848_netif.ip_addr.addr>>8);
- send_buff[pos++]=(unsigned char)(DP83848_netif.ip_addr.addr>>16);
- send_buff[pos++]=(unsigned char)(DP83848_netif.ip_addr.addr>>24);
- //MAC
- send_buff[pos++]=MACaddr[0];
- send_buff[pos++]=MACaddr[1];
- send_buff[pos++]=MACaddr[2];
- send_buff[pos++]=MACaddr[3];
- send_buff[pos++]=MACaddr[4];
- send_buff[pos++]=MACaddr[5];
- //Íø¹Ø
- send_buff[pos++]=(unsigned char)(DP83848_netif.gw.addr);
- send_buff[pos++]=(unsigned char)(DP83848_netif.gw.addr>>8);
- send_buff[pos++]=(unsigned char)(DP83848_netif.gw.addr>>16);
- send_buff[pos++]=(unsigned char)(DP83848_netif.gw.addr>>24);
-
- //×ÓÍøÑÚÂë
- send_buff[pos++]=(unsigned char)(DP83848_netif.netmask.addr);
- send_buff[pos++]=(unsigned char)(DP83848_netif.netmask.addr>>8);
- send_buff[pos++]=(unsigned char)(DP83848_netif.netmask.addr>>16);
- send_buff[pos++]=(unsigned char)(DP83848_netif.netmask.addr>>24);
-
- send_buff[pos++]=0xEF;
- send_buff[pos++]=0xFE;
-
- payload_len = pos;
- index = netbuf_alloc(buf_send, payload_len);
- memcpy (index,send_buff,payload_len);
-
- ret=netconn_sendto(bc_clientconn ,buf_send,IP_ADDR_BROADCAST,11009); //·¢ËÍÊý¾Ý
- netbuf_delete(buf_send);
- buf_send=NULL;
- netconn_delete(bc_clientconn); //ɾ³ýÁ¬½Ó
- }
复制代码
我做了测试,当我屏蔽 ret=netconn_sendto(bc_clientconn ,buf_send,IP_ADDR_BROADCAST,11009); 发送这句,就不会断网,ping一直能通
求各位大神帮忙看一下,TCP、udp能同时用吗在stm32上?有没有什么特殊需要设置的地方,小弟新人,求各位大神指教!!!
|
评分
查看全部评分
试试分时操作,比如:
做个计数器,为0时,执行 TCP,然后+1
为1时,执行UDP,然后+1
为2时,执行其它,
如此累推,当读数器到最后一组操作后,
读数器清零,重新读数。
这样,就不会阻塞了。
评分
查看全部评分