Windows Programming Socket issues

Source: Internet
Author: User

Today, debugging an MFC network program, the bug bothered the day, and finally resolved before the end of the call.

In general, we need to use the host computer to remotely control the machine car ahead. The keyboard key response of the MFC app on the PC is as follows: When the button is pressed, the system sends a message to the app, and when the button is lifted, another message is sent to the app. Our project is the use of keyboard keys, when the "up" arrow key, the host computer through the socket to the industrial computer to send a forward command, when the "upward" direction key, the upper computer through the socket to the industrial computer to send a forward stop command. As a result, when we quickly "press and lift" the up button, the robot is still moving forward, need to press the forward button again to continue to control, this is a very serious bug. At first, we thought there was a problem with the message response mechanism of Windows, and it was not allowed to press and hold the button quickly, otherwise it might ignore the raised message or treat the raised message as a pressed message. Later found that this is not the problem, the speed of the person's hands at a faster pace will not affect the Windows message processing, CPU execution speed is fast. Finally, it is found that the problem is here, because the message response function is pressed and lifted inside there are network send function send (these two send belong to the same socket). When pressed and lifted too fast, these two send functions may be problematic or cause problems with the receive function on the receiving end, so we have added a half-second delay before the send call in the "lifted" message response function to resolve the error.

Related Article

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.