Socket programming in windows

Source: Internet
Author: User

Today, I debugged an MFC Network Program, which had been plagued by bugs for a day and finally solved the problem before the job was closed.

In general, we need to use the host computer to remotely control the vehicle. The keyboard response of the MFC app on the host computer is as follows: when the button is pressed, the system sends a message to the app. When the button is lifted, the system sends another message to the app. This is how our project uses keyboard keys. When the "up" direction key is pressed, the host computer sends a forward command to the industrial computer through socket. When the "up" direction key is raised, the host computer sends a forward stop command to the IPC through socket. As a result, when we quickly press and raise the up button, the robot is still moving forward. We need to press the forward button to continue control. This is a very serious bug. At first, we thought that there was a problem with the message response mechanism of windows. We could not press and hold up the buttons quickly, otherwise, it may ignore the lifted message or treat the lifted message as the pressed message. Later, it was found that this was not the case. The speed of manual pressing would not affect the message processing in windows, and the cpu execution speed would be fast. Finally, the problem was discovered here, because the network sending function send (the two send belong to the same socket) is included in the message response function that is pressed and lifted ). However, if the press and lift speed is too fast, the two send functions may have problems or cause problems with the receive function at the receiving end, therefore, we added a half-second delay before sending the call in the "lifted" message response function to solve the error.

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.