Use and usage of W5500 keep-alive--Xinhua Dragon Electronics

Source: Internet
Author: User

Have you ever encountered such a problem, W5500 as the server has established a connection, suddenly the network cable dropped, and then to connect W5500, not even on the. Why? To explain the problem and propose a solution.

Figure 1 The host computer program as a client, connected to the W5500 server.

Figure 2 is a description of the Wireshark capture package for this issue. Where 192.168.11.114 is W5500 's ip,192.168.11.110 for the PC's IP. The 48th package is the first handshake: when the connection is established, the client sends the SYN packet to the server, waits for the server to confirm, and the 49th package is the second handshake: the server receives the SYN packet and must confirm that the customer's SYN also sends a SYN packet, that is, the Syn+ack packet. The 50th package is the third handshake: the client receives the server's Syn+ack packet, sends the acknowledgment packet ack to the server, the packet is sent, the client and the server enter the established state, and the handshake is completed three times. In the 70th package, the PC sends 9 bytes of data to the W5500, and in the 73rd package, W5500 sends 9 bytes of data to the PC. At this time, suddenly unplug the network cable, and click on the figure 1 "Disconnect" button, figure 1 in the 160th package shows that the PC sends Fin+ack packet, the 161th packet, W5500 send the answer. Then connect the cable, and click on the "Connect" in Figure 3, but cannot connect.

This is because, the network cable does not fall before, W5500 in the sock_established state, at this time suddenly unplug the network cable, the socket status has not changed, or sock_established State, no monitoring, so can not connect again.

Figure 1 Wireshark Grab Bag

Figure 2 The host computer establishes the connection

Figure 3 The network cable is dropped, and then plugged in the cable is not connected

Workaround:

The SN_KPALVTR register configures the keep-alive packet transmission interval for socket n. Only takes effect in TCP mode, with a unit time of 5 seconds. The keep-alive packet is transmitted after the SN-SR register has changed to sock_established and at least once received or sent by the other party. If sn_kpalvtr>0,w5500 automatically transmits the Keep-alive package after the set interval to check the connection status of TCP (automatic online inspection), the connection will be closed and trigger a timeout interrupt if the other party cannot respond to the Keep-alive package during the timeout count period. If ' SN_KPALVTR = 0 ', automatic online authentication will not be initiated, and the host can send keep-alive packets (manual online validation) by writing the Send_keep command to the register SN-CR. In ' sn_kpalvtr> 0 ', manual online verification will be disregarded.

Automatic inspection: Only in the main function, the register SN_KPALVTR write to the number of not 0, you can start the automatic online inspection. Write the following function in the function, then after the W5500 and the other data communication, after 10 seconds W5500 automatically send keep-alive packet.

Example: Voidsetkeepalive (SOCKET s)

{

Iinchip_write (SN_KPALVTR (s), 0x02);

}

Wireshark Grab Bag 4

1-3 packets is three handshake process, 5-10 packets is the process of sending and receiving data, 19 packets is W5500 to the PC to send the keep-alive package, 20 packets is the PC response to the keep-alive package. After 10 seconds, it is the 30th package, and W5500 sends a keep-alive packet again. Unplug the network cable at this time and click "Disconnect". After 10 seconds, the keep-alive packet sent by W5500 is unresponsive and the socket is closed. Then connect the network cable, click the "Connect" button, you can reestablish the connection, 109-111 packets is the second time to establish the connection process.

Figure 4 The connection can be re-established after Keep-alive is enabled

The above shows the process of automatically sending the Keep-alive package, if you want to send the Keep-alive package manually, write the SN_KPALVTR register to 0, when the Send_keep command is written to SN-CR, W5500 sends the keep-alive packet once.

Voidsend_ka (SOCKET s)

{

Iinchip_write (SN_CR (s), sn_cr_send_keep);

Return

}

by Catherine

Program Download: http://wizwiki.net/forum/viewtopic.php?f=90&t=1072 more W5500 questions, please contact Xinhua Dragon Electronic Technical engineer or visit: http://www.xhl.com.cn/ Ylogin/w5500.asp!

 

Use and usage of W5500 keep-alive--Xinhua Dragon Electronics

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.