struct tcp_pcb *tpcb=NULL;//tcp_client_init中绑定 连接
void check_tcp_connection(void)
{
if (tpcb == NULL || tcp_sndbuf(tpcb) == 0)
{
// PCB 为 NULL 或者没有可发送缓冲区,假定未连接
tcp_client_init(); // 尝试重新连接
printf("重新初始化");
return;
}
static int count;
if (tpcb->state != ESTABLISHED)
{
count++;
}
if(count>1000000)//超时处理
{
tcp_abort(tpcb);
tcp_client_init(); // 尝试重新连接
count=0;
printf("尝试重连\r\n");
}
}
LWIP TCP客户端超时重连
最新推荐文章于 2025-03-11 15:39:10 发布