Error 10054 when UDP connection is reset in Windows

Source: Internet
Author: User
Tags connection reset

Because of this problem, I would like to ask Microsoft. Other people on the Internet have similar problems, and I have encountered such problems. There is no good solution. This problem is exclusive to Winsock (at least all problems are under Windows ). Generally, when UDP socket is used, we send data, regardless of whether it arrives or not, and UDP is not connection-oriented. Therefore, when we receive this error, we may feel very strange: "Connection Reset 10054 ".

This error is generally received when UDP socket is used for acceptance (I will not talk about the specific language here, whether you use C #, Python or C, there will be similar problems in windows, as long as you call functions like receivefrom ). This is the last send operation sent to an address, but the address does not have a socket listener (for example, the peer crashes), then the ICMP control protocol will send us a port unreachable error, of course, this error should contain the detailed address of the other party and other information, but Winsock converts this error to Connection Reset, which will cause an exception when you call the next read operation, I didn't give you the details. For example, the recipient's address received by C # Is 0.0.0.0.

The most terrible problem is that if you do not take any measures, this exception will occur every time you call a read operation! The only way to restore normal is to turn off the socket and re-open it. This is terrible: You need to implement a UDP server and send the received audio to all customers. If a customer crashes or the network is poor, your send will not go wrong, but you encountered a problem during receive! Okay, you caught the exception, re-receive, or exception! Okay, you should switch off the socket and re-establish it, but you don't know which customer has a problem, therefore, you cannot remove the address from the sending list in time (even if you use heartbeat detection, it will take several seconds). The next time you send the address, you will not stop creating a socket, who suffered it?

In the discussion on the network, either this is a bug or the following code is used (take C # as an example)

const int SIP_UDP_CONNRESET=-1744830452;
socket.IOControl(SIP_UDP_CONNRESET, new byte[] {0, 0, 0, 0}, null);

Set this option to ignore the reset error, so you do not need to re-build the socket, but each time the socket will send packets to some closed customers, wasting server resources. You can only use other mechanisms to determine that the client has been disconnected, after a delay of some time, you can determine which client has a problem.

What I want to tell Microsoft is that you should throw an exception in the case of a problem. Otherwise, you can give the detailed error, no more, don't force a mistake. The entire socket will be destroyed, and the result will not be done. The default behavior is not a normal UDP behavior, and the error type is changed. It is really unsmoking!

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.