- 浏览: 1504439 次
- 性别:
- 来自: 南京
文章分类
- 全部博客 (419)
- XMPP (19)
- Android (180)
- Java (59)
- Network (4)
- HTML5 (13)
- Eclipse (9)
- SCM (23)
- C/C++ (4)
- UML (4)
- Libjingle (15)
- Tools&Softwares (29)
- Linphone (5)
- Linux&UNIX (6)
- Windows (18)
- Google (10)
- MISC (3)
- SIP (6)
- SQLite (5)
- Security (4)
- Opensource (29)
- Online (2)
- 文章 (3)
- MemoryLeak (10)
- Decompile (5)
- Ruby (1)
- Image (1)
- Bat (4)
- TTS&ASR (28)
- Multimedia (1)
- iOS (20)
- Asciiflow - ASCII Flow Diagram Tool.htm (1)
- Networking (1)
- DLNA&UPnP (2)
- Chrome (2)
- CI (1)
- SmartHome (0)
- CloudComputing (1)
- NodeJS (3)
- MachineLearning (2)
最新评论
-
bzhao:
点赞123!
Windows的adb shell中使用vi不乱码方法及AdbPutty -
wahahachuang8:
我觉得这种东西自己开发太麻烦了,就别自己捣鼓了,找个第三方,方 ...
HTML5 WebSocket 技术介绍 -
obehavior:
view.setOnTouchListenerview是什么
[转]android 一直在最前面的浮动窗口效果 -
wutenghua:
[转]android 一直在最前面的浮动窗口效果 -
zee3.lin:
Sorry~~
When I build "call ...
Step by Step about How to Build libjingle 0.4
http://support.microsoft.com/kb/263823/en-us
http://hi.baidu.com/jetqu2003/blog/item/397700031435e9703812bbcc.html
用Socket API 的 UDP做了一个c/s结构的通信程序,client启动后会向server发送一个请求,而server启动后也会向每个记录的client发送一个请 求,当server和client在同一台机器上时,server端发送给client端(实际是自己的地址)请求后,server自己会收到该请求,并 报错:recvfrom error 10054。(但实际上server 在sendto时,指定的是client的port,而非server的port)。解决办法:
1.头文件中加入下面代码:
#include <Winsock2.h>
#pragma comment(lib,"ws2_32.lib")
#define IOC_VENDOR 0x18000000
#define _WSAIOW(x,y) (IOC_IN|(x)|(y))
#define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12)
2.在创建socket之后加入下面代码:
DWORD dwBytesReturned = 0;
BOOL bNewBehavior = FALSE;
DWORD status;
status = WSAIoctl(m_hSock, SIO_UDP_CONNRESET,
&bNewBehavior,
sizeof (bNewBehavior),
NULL, 0, &dwBytesReturned,
NULL, NULL);
----------------------------------------------
具体原理参见下面这篇MSDN的文章
Knowledge Base Articles
-------------------------------------------------------
WinSock Recvfrom() Now Returns WSAECONNRESET Instead of Blocking or Timing Out
Q263823
--------------------------------------------------------------------------------
The information in this article applies to:
Microsoft Windows 2000 Professional
Microsoft Windows 2000 Server
Microsoft Windows 2000 Advanced Server
--------------------------------------------------------------------------------
SYMPTOMS
In Windows 2000, a User Datagram Protocol (UDP)
program may not work and may generate a WSAECONNRESET
response.
CAUSE
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. In Microsoft Windows NT 4.0, this situation
causes the select function to block or time out.
RESOLUTION
To resolve this problem, obtain the latest service
pack for Windows 2000. For additional information, please
see the following article in the Microsoft Knowledge
Base:
Q260910 How to Obtain the Latest Windows 2000 Service Pack
A new sockets IOCTL called "SIO_UDP_CONNRESET" has been
introduced in Windows 2000. When this IOCTL is used,
the program must be rewritten specifically for Windows
2000 to obtain the original Windows NT 4.0 behavior.
Windows NT 4.0, Microsoft Windows 95, and Microsoft
Windows 98 have no support for this new IOCTL. In
addition to rewriting your application, you will need
the hotfix referenced further down in this article.
The following code snippet demonstrates a technique that
can be used to call WSAIoctl with the
SIO_UDP_CONNRESET control code to obtain the original
Windows NT 4.0 behavior:
DWORDdwBytesReturned = 0;
BOOLbNewBehavior = FALSE;
DWORDstatus;// disable new behavior using
// IOCTL: SIO_UDP_CONNRESET
status = WSAIoctl(sd, SIO_UDP_CONNRESET,
&bNewBehavior, sizeof(bNewBehavior),
NULL, 0, &dwBytesReturned,
NULL, NULL);if (SOCKET_ERROR == status)
{
DWORD dwErr = WSAGetLastError();
if (WSAEWOULDBLOCK == dwErr)
{
// nothing to do
return(FALSE);
}
else
{
printf("WSAIoctl(SIO_UDP_CONNRESET) Error: %d\n", dwErr);
return(FALSE);
}
}
To be able to compile this code, you need either
to have the latest Mswsock.h which includes the
definition of SIO_UDP_CONNRESET or to insert below
definition of it directly into your code:
// MS Transport Provider IOCTL to control
// reporting PORT_UNREACHABLE messages
// on UDP sockets via recv/WSARecv/etc.
// Path TRUE in input buffer to enable (default if supported),
// FALSE to disable.
#defineSIO_UDP_CONNRESET_WSAIOW(IOC_VENDOR,12)
NOTE: The hotfix that is described in this article
will not resolve the problem unless the program is
rewritten to use the new SIO_UDP_CONNRESET IOCTL.
In order to compile this code, it is necessary to
have the latest Platform SDK installed on your computer.
This is available from the following MSDN Web site:
http:\\msdn.microsoft.com
For additional information, click the article number
below to view the article in the Microsoft Knowledge
Base:
Q263823 WinSock Recvfrom() Now Returns WSAECONNRESET Instead of Blocking or Timing Out
STATUS
Microsoft has confirmed this to be a problem in the
Microsoft products that are listed at the beginning of
this article. This problem was first corrected in
Windows 2000 Service Pack 2.
MORE INFORMATION
For additional information about how to install Windows
2000 and Windows 2000 hotfixes at the same time,
click the article number below to view the article in
the Microsoft Knowledge Base:
Q249149 Installing Microsoft Windows 2000 and Windows 2000 Hotfixes
Additional query words:
Keywords : kbWin2000PreSP2Fix kbWin2000SP2Fix
Issue type : kbbug
Technology : kbwin2000AdvServ kbwin2000AdvServSearch
kbwin2000Serv kbwin2000ServSearch kbwin2000Search
kbwin2000ProSearch kbwin2000Pro kbWinAdvServSearch
发表评论
-
Compile NSIS scripts in Linux
2014-10-16 12:29 2040http://blog.alejandrocelaya.co ... -
Process Explorer
2012-02-23 21:32 1326http://technet.microsoft.com/en ... -
Unlocker
2012-02-23 21:24 1224http://www.emptyloop.com/unlock ... -
Batch: %time% won't update in loop
2012-02-22 11:57 1254I got a problem with a batch-fi ... -
bat2exe
2012-02-21 11:14 1358Bat To Exe Converter Bat To ... -
FileMenu Tools
2012-02-21 11:01 964http://www.lopesoft.com/ ... -
批处理进度条
2012-02-09 20:26 2867@echo off echo. echo. echo. ... -
Microsoft Excel Scripts
2012-02-09 19:46 1139http://www.activexperts.com/net ... -
批处理之家
2012-02-09 19:45 1473http://bbs.bathome.net/index.ph ... -
使用setx一次性设置系统环境变量
2012-02-03 10:03 5903Setx.exe 批处理文件:javaEnv.bat ... -
批处理如何提取文件位置和文件名 不包括后缀
2012-02-02 14:01 16866比如我已经得到一个文 ... -
批处理延时启动的几个方法
2011-02-20 14:04 26178方法一:ping 缺点:时间精度为1秒,不够精确 @echo ... -
Sockets/Windows Sockets错误码
2011-02-19 22:56 1953Sockets/Windows Sockets错误 ... -
Microsoft Windows SDK for Windows 7 and .NET Framework 4
2011-02-17 20:48 3655Overview http://msdn.microsoft. ... -
关于Platform SDK和Windows SDK
2011-02-16 20:24 2493问题1:什么是Windows SDK? Windows ... -
各种GNU for Windows的包
2011-02-15 15:54 0GConf/ 2 ... -
[How To] Open Dos Prompt Command Here in Windows 7, and more
2011-02-14 14:03 1951If you like the power toy “Open ... -
笔记本电脑只有一个分区,如何分多个区
2011-02-14 14:00 3181http://www.itf4.com/computer-ti ...
相关推荐
26. WSAECONNRESET (10054):该错误码表示连接被重置。 27. WSAENOBUFS (10055):该错误码表示缓冲区不足。 28. WSAEISCONN (10056):该错误码表示已经连接。 了解这些错误码可以帮助开发者更好地处理网络错误和...
8. **错误处理**:Socket编程中常见的错误如WSAECONNRESET、WSAEWOULDBLOCK等,需要正确处理这些错误以确保程序的健壮性。 9. **多线程与异步编程**:在VC++中,可以利用多线程或者异步I/O模型(如WSAAsyncSelect或...
在Windows系统中,Winsock是SOCKET API的实现,它遵循BSD套接字模型并为开发者提供了创建TCP/IP网络应用的能力。 在VC下进行SOCKET编程,首先需要初始化Winsock。这通常通过调用`WSAStartup`函数完成,该函数会加载...
错误检查是必不可少的,常见的错误如WSAECONNREFUSED(连接被拒绝)、WSAECONNRESET(连接被重置)等,都需要进行适当的处理。 在源代码实例中,可能会包括以下部分: 1. 客户端程序:创建SOCKET,连接到服务器,...
8. **错误处理**:在整个过程中,要时刻关注并处理可能出现的错误,如WSAEWOULDBLOCK、WSAECONNRESET等,这些错误信息可以帮助我们定位和解决问题。 异步Socket通信例程的代码通常包含以下几个部分:初始化Winsock...
这些函数在遇到问题时返回一个错误代码,该代码可以被用来识别并解决程序中的错误。下面我们将详细介绍这三个函数以及它们返回的错误值。 1. **GetLastError**: `GetLastError` 是 Windows API 的一个函数,用于...
例如,`WSAGetLastError()`可以获取最近的错误代码,`WSACleanup()`用于在程序结束时清理Winsock环境。常见的错误如WSAECONNRESET表示连接被远程主机重置,WSAEWOULDBLOCK表示当前操作不允许,需要重试。 **七、...
6. **错误处理**:了解常见的网络错误,如WSAEWOULDBLOCK(操作将阻塞)、WSAECONNRESET(连接被重置)等,以及如何通过`WSAGetLastError()`获取错误信息。 7. **套接字选项和控制消息**:使用`setsockopt()`和`...
7. **错误处理**:Winsock2提供了丰富的错误代码,如WSAECONNRESET、WSAEWOULDBLOCK等,可以帮助开发者诊断并解决网络编程中遇到的问题。 8. **套接字选项**:`setsockopt`和`getsockopt`函数允许设置或获取套接字...
Winsock错误代码(如WSAEINVAL、WSAECONNRESET等)提供了关于网络通信失败原因的详细信息,帮助开发者调试程序,解决网络连接问题。 6. **《WINDOWS网络编程技术》**:这本书可能深入介绍了上述概念,并提供了详细...
Winsock提供了一套错误代码,如WSAECONNRESET、WSAEWOULDBLOCK等,开发者需要适当地捕获和处理这些错误。 9. **多线程与异步编程**:对于高性能服务器,通常会使用多线程或多进程处理并发连接,或者利用异步I/O模型...
- 在Winsock编程中,错误检查至关重要,常见的错误代码如WSAECONNRESET、WSAEWOULDBLOCK等需要适当地处理。 - VC6的调试器可以用来追踪代码执行,查看内存状态,以及设置断点,帮助找出程序中的问题。 通过深入...
本节将深入探讨Windows Socket(Winsock)API的使用,以及在实际开发中可能遇到的各种挑战和解决方案。 首先,我们了解Socket的基础概念。Socket是进程间通信(IPC)的一种方式,特别是在网络环境下,它允许不同...
4. **错误处理**:Windows Socket API提供了丰富的错误代码,如WSAECONNRESET表示连接被远程主机重置,WSAEWOULDBLOCK表示操作将阻塞等。开发者需要正确处理这些错误,确保程序的健壮性。 **高级特性** 1. **多...
5. **错误处理与调试**:Windows网络编程中,理解并正确处理各种网络错误是必不可少的,例如WSAEWOULDBLOCK、WSAECONNRESET等。同时,学会使用调试工具如Visual Studio Debugger,可以帮助定位和解决问题。 6. **...
CAsyncSocket类提供了各种错误代码,例如WSAECONNRESET表示连接被远程主机重置,WSAENETDOWN表示网络子系统失效等。在编程过程中,我们需要捕获并适当地处理这些错误。 五、关闭与清理 在完成通信后,记得关闭套接...
WinSocket提供了丰富的错误代码,如WSAECONNRESET表示连接被重置等,需要根据这些错误进行适当的处理。 通过学习本教程,你将掌握WinSocket高级实现技巧,能够独立构建一个功能完备的网络聊天室,从而进一步提升你...
理解并正确处理Winsock API的错误代码,如WSAECONNRESET、WSAEWOULDBLOCK等,可以帮助定位和解决问题。同时,使用调试工具如Visual Studio的调试器或第三方网络监控工具,可以辅助分析网络通信中的问题。 8. **网络...
Winsock提供了一系列的错误代码,如WSAECONNREFUSED(连接被拒绝),WSAECONNRESET(连接被重置)等,开发者需要根据这些错误码进行适当的错误处理。 9. **多线程与异步编程** 在实际应用中,可能需要处理多个并发...