Reconnect after LWIP is disconnected (hot swapping problem)

Source: Internet
Author: User
Tags keep alive

Recently, with the stm32 + LWIP protocol, the network cannot be reconnected when the network is unplugged. I found a lot of methods on the Internet, but it was really depressing! Later, I accidentally saw a solution to this problem temporarily. Although it was not so perfect, it was the best solution. Share with you.


Problem: LWIP creates a TCP server, and the data can be sent and received normally. But the client is abnormally disconnected-if the client loses power, the client's network cable is suddenly unplugged, and then the server is reconnected, the connection will fail.


Cause: lwip_close (), in the case of abnormal disconnection, I do not know what is still occupying the memory and cannot release resources normally. If you know how to release the instance, give me some advice.


My method is to use the keep alive feature provided by the protocol stack to automatically detect whether the network is offline and release resources. The LWIP callback mechanism is used to call the acept function every time the connection is established successfully, and a flag is added to the function to determine whether the connection is successful.


Add

// Network disconnection Detection

If (eth_readphyregister (phy_address, phy_bsr) & phy_linked_status) = 0x00) | (Listen 45_counter ))
{
Listen 45_counter = 1; // dropped flag

}

In

Static err_t tcpsvrpoll (void * Arg, struct tcp_pcb * PCB)
{

// Add

If (distinct 45_counter)
{
Tcp_keepalive (PCB );
}

}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.