socket错误码
socket error 10053,10054究竟是怎么引起的

贴2段能稳定重现10053的代码,下面是客户端:[cpp]view plaincopy1.WORD VersionRequested;2.WSADATA WsaData;3.4.VersionRequested = MAKEWORD(2, 2);5.6.if (WSAStartup(VersionRequested, &WsaData))7.return -1;8.9.SOCKET SocketServer = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);10.SOCKADDR_IN AddrServer;11.AddrServer.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");12.AddrServer.sin_port = htons(9999);13.AddrServer.sin_family = AF_INET;14.15.// 连接服务器16.if (0 != connect(SocketServer, (SOCKADDR *)&AddrServer, sizeof(SOCKADDR)))17.{18. closesocket(SocketServer);19.return false;20.}21.22.int err = 0;23.char temp[] = "hello, server";24.int rs = send(SocketServer, temp, sizeof(temp) + 1, 0);25.26.char buff[1024] = {0};27.rs = recv(SocketServer, buff, sizeof(buff), 0);28.29.// 下面这2句代码如果注释掉,后面的recv就能正解的返回0。
如果不注释掉,recv就会返回-1,30.// 并得到10053这个错误31.rs = send(SocketServer, temp, sizeof(temp) + 1, 0);32.err = WSAGetLastError();33.34.rs = recv(SocketServer, buff, sizeof(buff), 0);35.err = WSAGetLastError();36.37.system("pause");38.return 0;这个是服务器的:[cpp]view plaincopy1.WORD VersionRequested;2.WSADATA WsaData;3.4.VersionRequested = MAKEWORD(2, 2);5.6.if (WSAStartup(VersionRequested, &WsaData))7.{8. printf("加载socket库失败!\n");9.return -1;10.}11.12.// 监听来自浏览器的请求13.SOCKET SockServer = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);14.SOCKADDR_IN AddrClient;15.AddrClient.sin_family = AF_INET;16.AddrClient.sin_addr.s_addr = INADDR_ANY;17.AddrClient.sin_port = htons(9999);18.19.if (SockServer == INVALID_SOCKET)20.{21. printf("socket初始化失败!\n");22. closesocket(SockServer);23. WSACleanup();24.return -1;25.}26.27.if (bind(SockServer, (sockaddr*)&AddrClient, sizeof(AddrClient)) != 0)28.{29. printf("socket绑定失败!\n");30. closesocket(SockServer);31. WSACleanup();32.return -1;33.}34.35.if (listen(SockServer, 10) != 0)36.{37. printf("socket监听失败!\n");38. closesocket(SockServer);39. WSACleanup();40.return -1;41.}42.43.while (1)44.{45. SOCKET NewSocket = accept(SockServer, NULL, NULL);46.if (INVALID_SOCKET == NewSocket)47. {48. closesocket(NewSocket);49.continue;50. }51.else52. {53.struct linger so_linger;54. so_linger.l_onoff = 1;55. so_linger.l_linger = 30;56. setsockopt(NewSocket ,SOL_SOCKET, SO_LINGER, (const char*)&so_linger, sizeof(so_linger));57. }58.59.char buff[1024];60.int rs = recv(NewSocket, buff, sizeof(buff), 0);61.62.char temp[] = "hello, client";63. rs = send(NewSocket, temp, sizeof(temp) + 1, 0);64.65. closesocket(NewSocket);66.}10053里说的software在我的例子中指的就是那个send函数吗,是send函数执行的时候,发现对方的套接字已经关闭了,所以它把己方的套接字也关掉了吗,然后导致后续的recv 报错10053?出现10053的原因是因为在你执行这次send的时候对端已经执行过closesocket了,而发送的数据还是被成功的推入了发送缓冲区中,因此返回了0,此时你可能还没得到FIN消息,而紧接着recv这边就得到了对端关闭socket的FIN消息,因此此时需要放弃发送缓冲中的数据,异常终止连接,所以得到了10053错误:您的主机中的软件中止了一个已建立的连接。
Socket编程协议错误代码解析

10004—WSAEINTR函数调用中断。
该错误表明由于对WSACancelBlockingCall的调用,造成了一次调用被强行中断。
10009—WSAEBADF文件句柄错误。
该错误表明提供的文件句柄无效。
在MicrosoftWindowsCE下,socket函数可能返回这个错误,表明共享串口处于“忙”状态。
10013—WSAEACCES权限被拒。
尝试对套接字进行操作,但被禁止。
若试图在sendto或WSASendTo中使用一个广播地址,但是尚未用setsockopt和SO_BROADCAST这两个选项设置广播权限,便会产生这类错误。
10014—WSAEFAULT地址无效。
传给Winsock函数的指针地址无效。
若指定的缓冲区太小,也会产生这个错误。
10022—WSAEINVAL参数无效。
指定了一个无效参数。
例如,假如为WSAIoctl调用指定了一个无效控制代码,便会产生这个错误。
另外,它也可能表明套接字当前的状态有错,例如在一个目前没有监听的套接字上调用accept或WSAAccept。
10024—WSAEMFILE打开文件过多。
提示打开的套接字太多了。
通常,Microsoft提供者只受到系统内可用资源数量的限制。
10035—WSAEWOULDBLOCK资源暂时不可用。
对非锁定套接字来说,如果请求操作不能立即执行的话,通常会返回这个错误。
比如说,在一个非暂停套接字上调用connect,就会返回这个错误。
因为连接请求不能立即执行。
10036—WSAEINPROGRESS操作正在进行中。
当前正在执行非锁定操作。
一般来说不会出现这个错误,除非正在开发16位Winsock应用程序。
10037—WSAEALREADY操作已完成。
一般来说,在非锁定套接字上尝试已处于进程中的操作时,会产生这个错误。
比如,在一个已处于连接进程的非锁定套接字上,再一次调用connect或WSAConnect。
另外,服务提供者处于执行回调函数(针对支持回调例程的Winsock函数)的进程中时,也会出现这个错误。
socket错误码(精品)

Sockets/Windows Sockets错误码Windows Sockets在头文件winsock.h中定义了所有的错误码,它们包括以“WSA”打头的Windows Sockets实现返回的错误码和Berkeley Sockets定义的错误码全集。
定义Berkeley Sockets错误码是为了确保原有软件的可移植性。
WSAEACCES (10013) Permission denied.试图使用被禁止的访问权限去访问套接字。
例如,在没有使用函数setsockopt()的SO_BROADCAST命令设置广播权限的套接字上使用函数sendto()给一个广播地址发送数据。
WSAEADDRINUSE (10048)Address already in use.正常情况下每一个套接字地址(协议/IP地址/端口号)只允许使用一次。
当应用程序试图使用bind()函数将一个被已存在的或没有完全关闭的或正在关闭的套接字使用了的IP地址/端口号绑扎到一个新套接字上时,该错误发生。
对于服务器应用程序来说,如果需要使用bind()函数将多个套接字绑扎到同一个端口上,可以考虑使用setsockopt()函数的SO_REUSEADDR命令。
客户应用程序一般不必使用bind()函数——connect()函数总是自动选择没有使用的端口号。
当bind()函数操作的是通配地址(包括ADDR_ANY)时,错误WSAEADDRINUSE可能延迟到一个明确的地址被提交时才发生。
这可能在后续的函数如connect()、listen()、WSAConnect()或WSAJoinLeaf()调用时发生。
WSAEADDRNOTAVAIL (10049)Cannot assign requested address.被请求的地址在它的环境中是不合法的。
通常地在bind()函数试图将一个本地机器不合法的地址绑扎到套接字时产生。
它也可能在connect()、sendto()、WSAConnect()、WSAJoinLeaf()或WSASendTo()函数调用时因远程机器的远程地址或端口号非法(如0地址或0端口号)而产生。
socket错误代码

socket错误代码Socket error 0 - Directly send errorSocket error 10004 - Interrupted function call⼀个封锁操作被对 WSACancelBlockingCall 的调⽤中断。
Socket error 10013 - Permission denied以⼀种访问权限不允许的⽅式做了⼀个访问套接字的尝试。
Socket error 10014 - Bad address系统检测到在⼀个调⽤中尝试使⽤指针参数时的⽆效指针地址。
Socket error 10022 - Invalid argument提供了⼀个⽆效的参数。
Socket error 10024 - Too many open files打开的套接字太多。
Socket error 10035 - Resource temporarily unavailable⽆法⽴即完成⼀个⾮阻⽌性套接字操作。
Socket error 10036 - Operation now in progress ⽬前正在执⾏⼀个阻⽌性操作。
Socket error 10037 - Operation already in progress 在⼀个⾮阻⽌性套接字上尝试了⼀个已经在进⾏的操作。
Socket error 10038 - Socket operation on non-socket 在⼀个⾮套接字上尝试了⼀个操作。
Socket error 10039 - Destination address required 请求的地址在⼀个套接字中从操作中忽略。
Socket error 10040 - Message too long ⼀个在数据报套接字上发送的消息⼤于内部消息缓冲区或其他⼀些⽹络限制,或该⽤户⽤于接收数据报的缓冲区⽐数据报⼩。
Socket error 10041 - Protocol wrong type for socket 在套接字函数调⽤中指定的⼀个协议不⽀持请求的套接字类型的语法。
SOCKET错误代码表

WSAEWOULDBLOCK (10035) 函式作用阻攔中
WSAETIMEDOUT (10060) Connection timed out
WSAHOST_NOT_FOUND (11001) Host not found
WSASYSNOTREADY (10091) Network sub-system is unavailable
WSANOTINITIALISED (10093) WSAStartup() not performed
Socket error 10050 - Network is down
Socket error 10051 - Network is unreachable
Socket error 10052 - Network dropped connection on reset
Socket error 10053 - Software caused connection abort
Socket error 10037 - Operation already in progress
Socket error 10038 - Socket operation on non-socket
Socket error 10039 - Destination address required
getstockname()
沒有呼叫bind()函式指定socket名稱
listen()
已經處於連接狀態或是socket沒有呼叫bind()函式指定socket名稱
recv()和recvfrom()
對於datagram socket,socket沒有呼叫bind()函式指定IP位址、port和協定等;對於stream socket,連接尚未建立
Socket的错误码和描述

Socket的错误码和描述Socket的错误码和描述(中英文翻译)//下面是Socket Error的错误码和描述:Socket error 0 - Directly send errorSocket error 10004 - Interrupted function //call 操作被终止Socket error 10013 - Permission denied //c访问被拒绝Socket error 10014 - Bad address //c地址错误Socket error 10022 - Invalid argument //参数错误Socket error 10024 - Too many open files // 打开太多的socketsSocket error 10035 - Resource temporarily unavailable // 没有可以获取的资料Socket error 10036 - Operation now in progress // 一个阻塞操作正在进行中Socket error 10037 - Operation already in progress // 操作正在进行中Socket error 10038 - Socket operation on non-socket //非法的socket对象在操作Socket error 10039 - Destination address required //目标地址错误Socket error 10040 - Message too long //数据太长Socket error 10041 - Protocol wrong type for socket //协议类型错误Socket error 10042 - Bad protocol option // 错误的协议选项Socket error 10043 - Protocol not supported //协议不被支持Socket error 10044 - Socket type not supported //socket类型不支持Socket error 10045 - Operation not supported //不支持该操作Socket error 10046 - Protocol family not supported //协议族不支持Socket error 10047 - Address family not supported by protocol family//使用的地址族不在支持之列Socket error 10048 - Address already in use //地址已经被使用Socket error 10049 - Cannot assign requested address //地址设置失败Socket error 10050 - Network is down //网络关闭Socket error 10051 - Network is unreachable //网络不可达Socket error 10052 - Network dropped connection on reset //网络被重置Socket error 10053 - Software caused connection abort //软件导致连接退出Socket error 10054 - connection reset by peer //连接被重置Socket error 10055 - No buffer space available //缓冲区不足Socket error 10056 - Socket is already connected // socket已经连接Socket error 10057 - Socket is not connected //socket没有连接Socket error 10058 - Cannot send after socket shutdown //socket已经关闭Socket error 10060 - Connection timed out //超时Socket error 10061 - Connection refused //连接被拒绝Socket error 10064 - Host is down //主机已关闭Socket error 10065 - No route to host // 没有可达的路由Socket error 10067 - Too many processes //进程太多Socket error 10091 - Network subsystem is unavailable //网络子系统不可用Socket error 10092 - WINSOCK.DLL version out of range//winsock.dll版本超出范围Socket error 10093 - Successful WSAStartup not yet performed //没有成功执行WSAStartupSocket error 10094 - Graceful shutdown in progress //Socket error 11001 - Host not found //主机没有找到Socket error 11002 - Non-authoritative host not found // 非授权的主机没有找到Socket error 11003 - This is a non-recoverable error //这是个无法恢复的错误Socket error 11004 - Valid name, no data record of requested type //请求的类型的名字或数据错误WSAEADDRINUSE (10048) Address already in useWSAECONNABORTED (10053) Software caused connection abortWSAECONNREFUSED (10061) Connection refusedWSAECONNRESET (10054) Connection reset by peerWSAEDESTADDRREQ (10039) Destination address required WSAEHOSTUNREACH (10065) No route to hostWSAEMFILE (10024) Too many open filesWSAENETDOWN (10050) Network is downWSAENETRESET (10052) Network dropped connectionWSAENOBUFS (10055) No buffer space availableWSAENETUNREACH (10051) Network is unreachableWSAETIMEDOUT (10060) Connection timed outWSAHOST_NOT_FOUND (11001) Host not foundWSASYSNOTREADY (10091) Network sub-system is unavailableWSANOTINITIALISED (10093) WSAStartup() not performed WSANO_DATA (11004) Valid name, no data of that typeWSANO_RECOVERY (11003) Non-recoverable query error WSATRY_AGAIN (11002) Non-authoritative host foundWSAVERNOTSUPPORTED (10092) Wrong WinSock DLL version。
socket错误详解

WSAEINTR (10004)∙翻译:中断函数调用。
∙说明:阻止操作被中断通过调用WSACancelBlockingCall (Wsapiref_704y.asp)。
WSAEACCES (10013)∙翻译:权限被拒绝。
∙说明:尝试访问套接字访问权限被禁止的方式。
例如,用于发送到广播的地址,但广播的权限未设置通过使用setsockopt(SO_BROADCAST) 时,将发生此错误。
另一个可能导致WSAEACCES 错误的原因是,当调用绑定(Wsapiref_6vzm.asp)函数(在Microsoft Windows NT 4.0 Service Pack 4 [SP4] 或更高版本),另一个程序、服务或内核模式驱动程序绑定到同一地址具有独占访问权。
这种独占的访问是一项新功能的Windows NT 4.0 SP4 和更高版本,并且它使用SO_EXCLUSIVEADDRUSE 选项的实现。
WSAEFAULT (10014)∙翻译:错误的地址。
∙说明:尝试使用指针参数的调用时,系统检测到一个无效的指针地址。
如果程序传递了无效的指针值,或者如果缓冲区的长度太小,则会发生此错误。
例如,如果一个参数,它是一种SOCKADDR 结构的长度小于sizeof(SOCKADDR) 的值,将发生此问题。
WSAEINVAL (10022)∙翻译:无效的参数。
∙说明:setsockopt (Wsapiref_94aa.asp) 函数提供了无效的参数(例如,指定参数的%)。
有时,它也就是从插座的当前状态,调用例如,未在侦听的套接字接受(Wsapiref_13aq.asp)。
WSAEMFILE (10024)∙翻译:打开的文件太多。
∙说明:有太多打开的套接字。
每个实现都可能具有套接字句柄可用的最大数目。
这些句柄可能会提供每个进程的全局,或每个线程。
WSAEWOULDBLOCK (10035)∙翻译:资源暂时不可用。
∙说明:将返回此错误,无法立即完成,例如,非阻塞套接字操作从接收(Wsapiref_2i9e.asp)时无数据排队要从套接字读取。
Windows Sockets 错误码及出错原因

EMSGSIZE
10040
同BSD
WSAEPROTOTYPE
EPROTOTYPE
10041
同BSD
WSAENOPROTOOPT
ENOPROTOOPT
10042
同BSD
WSAEPROTONOSUPPORT
EPROTONOSUPPORT
10043
同BSD
WSAESOCKTNOSUPPORT
NO_RECOVERY
11003
同BSD
WSANO_DATA
NO_DATA
11004
同BSD
A.2Windows Sockets错误码扩展描述
下面给出WSAGetLastError()函数返回的可能错误码按字母顺序排列的列表,同时给出简要的扩展描述。
WSAEACCES (10013) Permission denied.
WSAEDESTADDRREQ (10039) Destination address required.
在套接字上一个操作所必须的地址被遗漏。例如,如果sendto()函数被调用且远程地址为ADDR_ANY时,此错误被返回。
WSAEFAULT (10014) Bad address.
系统检测到调用试图使用的一个指针参数指向的是一个非法指针地址。如果应用程序传递一个非法的指针值,或缓冲区长度太小,此错误发生。例如,参数为结构sockaddr,但参数的长度小于sizeof(struct sockaddr)。
试图和一个不可达主机进行套接字操作。参见WSAENETUNREACH。
WSAEINPROGRESS (10036) Operation now in progress.
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
errno.00 is: Error 0errno.01 is: Not ownererrno.02 is: No such file or directory errno.03 is: No such processerrno.04 is: Interrupted system callerrno.05 is: I/O errorerrno.06 is: No such device or address errno.07 is: Arg list too longerrno.08 is: Exec format errorerrno.09 is: Bad file numbererrno.10 is: No child processeserrno.11 is: Resource temporarily unavailable errno.12 is: Not enough spaceerrno.13 is: Permission deniederrno.14 is: Bad addresserrno.15 is: Block device requirederrno.16 is: Device busyerrno.17 is: File existserrno.18 is: Cross-device linkerrno.19 is: No such deviceerrno.20 is: Not a directoryerrno.21 is: Is a directoryerrno.22 is: Invalid argumenterrno.23 is: File table overflowerrno.24 is: Too many open fileserrno.25 is: Not a typewritererrno.26 is: Text file busyerrno.27 is: File too largeerrno.28 is: No space left on device errno.29 is: Illegal seekerrno.30 is: Read-only file systemerrno.31 is: Too many linkserrno.32 is: Broken pipeerrno.33 is: Argument out of domain errno.34 is: Result too largeerrno.35 is: No message of desired type errno.36 is: Identifier removederrno.37 is: Channel number out of range errno.38 is: Level 2 not synchronized errno.39 is: Level 3 haltederrno.40 is: Level 3 reseterrno.41 is: Link number out of range errno.42 is: Protocol driver not attached errno.43 is: No CSI structure availableerrno.44 is: Level 2 haltederrno.45 is: Deadlock condition if locked errno.46 is: Device not readyerrno.47 is: Write-protected mediaerrno.48 is: Unformatted or incompatible media errno.49 is: No locks availableerrno.50 is: Cannot Establish Connection errno.51 is: Connection Downerrno.52 is: Missing file or filesystemerrno.53 is: Requests blocked by Administrator errno.54 is: Operation would blockerrno.55 is: Operation now in progresserrno.56 is: Operation already in progress errno.57 is: Socket operation on non-socket errno.58 is: Destination address required errno.59 is: Message too longerrno.60 is: Protocol wrong type for socket errno.61 is: Protocol not availableerrno.62 is: Protocol not supportederrno.63 is: Socket type not supportederrno.64 is: Operation not supported on socket errno.65 is: Protocol family not supported errno.66 is: Addr family not supported by protocol errno.67 is: Address already in useerrno.68 is: Can't assign requested address errno.69 is: Network is downerrno.70 is: Network is unreachableerrno.71 is: Network dropped connection on reset errno.72 is: Software caused connection abort errno.73 is: Connection reset by peererrno.74 is: No buffer space availableerrno.75 is: Socket is already connectederrno.76 is: Socket is not connectederrno.77 is: Can't send after socket shutdown errno.78 is: Connection timed outerrno.79 is: Connection refusederrno.80 is: Host is downerrno.81 is: No route to hosterrno.82 is: Restart the system callerrno.83 is: Too many processeserrno.84 is: Too many userserrno.85 is: Too many levels of symbolic links errno.86 is: File name too longerrno.87 is: Directory not emptyerrno.88 is: Disk quota exceedederrno.89 is: Invalid file system control data detected errno.90 is: For future useerrno.91 is: For future useerrno.92 is: For future useerrno.93 is: Item is not local to hosterrno.94 is: For future useerrno.95 is: For future useerrno.96 is: For future useerrno.97 is: For future useerrno.98 is: For future useerrno.99 is: For future useerrno.100 is: For future useerrno.101 is: For future useerrno.102 is: For future useerrno.103 is: For future useerrno.104 is: For future useerrno.105 is: For future useerrno.106 is: For future useerrno.107 is: For future useerrno.108 is: For future useerrno.109 is: Function not implementederrno.110 is: Media surface errorerrno.111 is: I/O completed, but needs relocation errno.112 is: No attribute founderrno.113 is: Security Authentication Denied errno.114 is: Not a Trusted Programerrno.115 is: Too many references: can't splice errno.116 is: Invalid wide charactererrno.117 is: Asynchronous I/O cancellederrno.118 is: Out of STREAMS resourceserrno.119 is: System call timed outerrno.120 is: Next message has wrong typeerrno.121 is: Error in protocolerrno.122 is: No message on stream head read q errno.123 is: fd not associated with a stream errno.124 is: Unsupported attribute valueerrno.125 is: Multihop is not allowederrno.126 is: The server link has been severed errno.127 is: Value too large to be stored in data type打印fangshiint nPrintErrno()/*打印socket错误*/{int i = 0;for(i = 0; i < 256; i++)printf("errno.%02d is: %s\n", i, strerror(i));return 0;}。