UDP Socket出现10054错误码的解决方法

来源:互联网 发布:我的世界版本 知乎 编辑:程序博客网 时间:2024/06/05 20:00

a) 10054错误描述:远程主机强迫关闭了一个现有的连接。

b) 微软提供的错误原因(英文):

If sending a datagram using the sendto function results in an ICMP port unreachable response and the select function is set for readfds, the program returns 1 and the subsequent call to the recvfrom function does not work with a WSAECONNRESET (10054) error response.

c) 微软提供的解决方法

添加“WINSOCK2.H”和“WS2_32.lib”文件。

添加如下代码:

#define IOC_VENDOR 0x18000000

#define _WSAIOW(x,y) (IOC_IN|(x)|(y))

#define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12)

 

DWORD  dwByteReturned = 0;

BOOL bNewBehavior = FALSE;

DWORD status;

 

status = WSAIoctl(sock, SIO_UDP_CONNRESET, &bNewBehavior, sizeof(bNewBehavior), NULL, 0, &dwByteReturned, NULL, NULL);

  注:WSAIoctl函数的第一个参数类型为SOCKET
0 0