This article is a mirror article of machine translation, please click here to jump to the original article.

View: 19287|Reply: 1

[Source] [Actual combat] UDP System.Net.Sockets.SocketException

[Copy link]
Posted on 3/9/2017 10:16:26 AM | | |
System.Net.Sockets.SocketException (0x80004005): The remote host forced an existing connection to close.   In System.Net.Sockets.Socket.ReceiveFrom(Byte[] b



During UDP communication, using try... catch statement always gets an error when accepting data:
System.Net.Sockets.SocketException (0x80004005): The remote host forced an existing connection to close.
The stupidest solution in the first place was to do nothing in the catch statement and let the listening port function continue to run. But this is not a long-term solution, and I searched online for a long time and found Microsoft's explanation.


Microsoft's explanation: http://support.microsoft.com/kb/263823

Solution:








Previous:Successfully performed a UDP hole [Reprint]
Next:Javascrip{filter}t window.print() sets the print style and content
 Landlord| Posted on 3/9/2017 10:17:54 AM |
After initializing the object, set the properties as follows:
                    uint IOC_IN = 0x80000000;
                    uint IOC_VENDOR = 0x18000000;
                    uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12;
//uc为接收数据所使用的UdpClient,不同程序自己手改
            uc. Client.IOControl((int)SIO_UDP_CONNRESET, new byte[] {Convert.ToByte(false)}, null);

Socket.IOControl method (IOControlCode, byte[], byte[])
Use IOControlCode to specify control code to set a low-level operating mode for the socket.
parameter
ioControlCode
An IOControlCode value that specifies the control code for the action to be performed.
optionInValue
An array of type Byte containing the input data required by the operation.
optionOutValue
An array of type Byte that contains the output data returned by the operation.
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com