日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

lwip的tcp断线重连例程_STM32F107+LWIP---如何检查tcp通讯断开?并重新连接

發布時間:2023/12/14 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 lwip的tcp断线重连例程_STM32F107+LWIP---如何检查tcp通讯断开?并重新连接 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

void LwIP_Init(void)

{

struct ip_addr ipaddr;? ? ? ? //IP地址

struct ip_addr netmask;? ? ? ? //子掩碼

struct ip_addr gw;? ?? ???//網關地址

uint8_t macaddress[6]={0,0,0,0,0,1};??//以太網控制器物理地址,即MAC地址

/* Initializes the dynamic memory heap defined by MEM_SIZE.*/

mem_init();

/* Initializes the memory pools defined by MEMP_NUM_x.*/

memp_init();

#if LWIP_DHCP

ipaddr.addr = 0;

netmask.addr = 0;

gw.addr = 0;

#else

IP4_ADDR(&ipaddr, 192, 168, 1, 200);

IP4_ADDR(&netmask, 255, 255, 255, 0);

IP4_ADDR(&gw, 192, 168, 1, 1);

#endif

Set_MAC_Address(macaddress);

/* - netif_add(struct netif *netif, struct ip_addr *ipaddr,

struct ip_addr *netmask, struct ip_addr *gw,

void *state, err_t (* init)(struct netif *netif),

err_t (* input)(struct pbuf *p, struct netif *netif))

Adds your network interface to the netif_list. Allocate a struct

netif and pass a pointer to this structure as the first argument.

Give pointers to cleared ip_addr structures when using DHCP,

or fill them with sane numbers otherwise. The state pointer may be NULL.

The init function pointer must point to a initialization function for

your ethernet netif interface. The following code illustrates it's use.*/

netif_add(&netif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);

/*??Registers the default network interface.*/

netif_set_default(&netif);

#if LWIP_DHCP

/*??Creates a new DHCP client for this interface on the first call.

Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at

the predefined regular intervals after starting the client.

You can peek in the netif->dhcp struct for the actual DHCP status.*/

dhcp_start(&netif);

#endif

/*??When the netif is fully configured this function must be called.*/

netif_set_up(&netif);

tcp_client_init();

}

/**

* @brief??Called when a frame is received

* @param??None

* @retval None

*/

void LwIP_Pkt_Handle(void)

{

/* Read a received packet from the Ethernet buffers and send it to the lwIP for handling */

ethernetif_input(&netif);

}

/**

* @brief??LwIP periodic tasks

* @param??localtime the current LocalTime value

* @retval None

*/

void LwIP_Periodic_Handle(__IO uint32_t localtime)

{

/* TCP periodic process every 250 ms */

if (localtime - TCPTimer >= TCP_TMR_INTERVAL)

{

TCPTimer =??localtime;

tcp_tmr();

}

/* ARP periodic process every 5s */

if (localtime - ARPTimer >= ARP_TMR_INTERVAL)

{

ARPTimer =??localtime;

etharp_tmr();

}

#if LWIP_DHCP

/* Fine DHCP periodic process every 500ms */

if (localtime - DHCPfineTimer >= DHCP_FINE_TIMER_MSECS)

{

DHCPfineTimer =??localtime;

dhcp_fine_tmr();

}

/* DHCP Coarse periodic process every 60s */

if (localtime - DHCPcoarseTimer >= DHCP_COARSE_TIMER_MSECS)

{

DHCPcoarseTimer =??localtime;

dhcp_coarse_tmr();

}

#endif

}

/**

* @brief??LCD & LEDs periodic handling

* @param??localtime: the current LocalTime value

* @retval None

*/

void Display_Periodic_Handle(__IO uint32_t localtime)

{

/* 250 ms */

if (localtime - DisplayTimer >= LCD_TIMER_MSECS)

{

DisplayTimer = localtime;

#if LWIP_DHCP

/* We have got a new IP address so update the display */

if (IPaddress != netif.ip_addr.addr)

{

/* Read the new IP address */

IPaddress = netif.ip_addr.addr;

/* Display the new IP address */

if (netif.flags & NETIF_FLAG_DHCP)

{

tcp_client_init();

}

}

else if (IPaddress == 0)

{

/* If no response from a DHCP server for MAX_DHCP_TRIES times */

/* stop the dhcp client and set a static IP address */

if (netif.dhcp->tries > MAX_DHCP_TRIES)

{

struct ip_addr ipaddr;

struct ip_addr netmask;

struct ip_addr gw;

dhcp_stop(&netif);

IP4_ADDR(&ipaddr, 192, 168, 1, 8);

IP4_ADDR(&netmask, 255, 255, 255, 201);

IP4_ADDR(&gw, 192, 168, 1, 1);

netif_set_addr(&netif, &ipaddr , &netmask, &gw);

}

}

#endif

}

}

總結

以上是生活随笔為你收集整理的lwip的tcp断线重连例程_STM32F107+LWIP---如何检查tcp通讯断开?并重新连接的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。