问题描述
我想测试一些网络错误情况,但我没有网线.TCP 客户端和服务器应用程序运行在同一系统上.
I would like to test some network error conditions, but I have no network cable. Both TCP client and server application running on the same system.
使用 TCPView 之类的工具关闭连接而不是拔掉网线会是一个真实的模拟吗?
Would it be a realistic simulation to use a tool like TCPView to close a connection, instead of unplugging the network cable?
更新:
- 使用 TCPView 断开连接会导致 10054 错误,这可以在应用程序代码中处理.10054 是 WSAECONNRESET - 连接已由对等方重置.这通常是连接另一端的问题.
我还从 这个答案 中了解到您可以拔掉网络然后重新插入,或者您的Wi-Fi 笔记本电脑可能会失去接收信号,然后再恢复.如果这种可恢复的情况在我们使用的所有程序中都被视为错误,那将是令人沮丧的."(参见:服务器套接字如何知道网络使用c ++在Windows中拔出电缆)
I have also learned from this answer that "You can unplug a network and then plug it back in, or your Wi-Fi laptop can lose reception for a second and then pick it back up. It would be frustrating if such resumable cases were treated as an error in all the programs we use." (See: how server socket know network cable in unplugged in windows using c++)
推荐答案
如果您尝试开始与外部 IP 连接,然后关闭 WLAN 怎么办?这对您来说可能是可以接受的.
What if you try to start connection with your external IP and then turn of WLAN? This may be acceptable for you.
如果您只想关闭客户端或服务器的连接,您可以限制与防火墙的连接.
If you want to close connection for only client or server you can restrict connection with firewall.
或者为什么不一个接一个地关闭 SERVER 应用程序和 CLIENT 应用程序?关闭客户端应用程序,您将看到失去连接后服务器应用程序发生了什么,反之亦然.如果关闭事件有什么事情,只需通过任务管理器结束任务.
Or why not just close SERVER app and CLIENT app one after another? Close client app and you'll see what's happening with server app after losing connection and vice versa. If there is something on close event just end task via task manager.
所有这些:
如果您同时运行 TCP 客户端和服务器应用程序系统
这篇关于如何模拟“插入的网络电缆"(TCP/IP)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!