简体   繁体   English

如何模拟客户端和服务器之间的套接字断开连接?

[英]How can I simulate a socket disconnection (on windows) between a client and a server?

I've implemented a kind of 'heartbeat solution' and I'd like to see what happen when the network 'goes down', in real conditions, specially if it happens when there is no traffic on the socket. 我已经实现了一种“心跳解决方案”,我希望看到在实际情况下网络“发生故障”时会发生什么,特别是如果套接字上没有流量时会发生这种情况。

Problems: - I've got only one computer; 问题: - 我只有一台电脑; - I'm on windows/java; - 我在windows / java上;

I guess that simply unplugging the network cable/deactivating the network card won't affect the two processes, as they are running on the same box; 我想只需拔掉网线/停用网卡就不会影响这两个进程,因为它们在同一个盒子上运行; Is there a programmatic solution to that? 是否有程序化解决方案? A kind of way to force close a socket ? 一种强制关闭套接字的方法?

我使用TCPView右键单击并关闭套接字。

如果您正在使用Eclipse,则有一个TCP / IP监视器,WIndow - > Show View - > Other - > type filter text = TCP / IP并创建一个新的转发tcp / ip,您可以监视并在中间停止它。

You can also simulate two computers with virtual computers. 您还可以使用虚拟计算机模拟两台计算机。

I use VirtualBox for making myself more computers :D. 我使用VirtualBox让自己更多的电脑:D。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何模拟套接字断开? - How can I simulate a socket disconnection? 如何在Java(Android)套接字通信中立即检测到服务器与客户端的断开连接 - How to detect the server disconnection to the client immediately in Java(Android) socket communication 套接字编程:客户端断开连接可使服务器挂起 - Socket Programming : Client Disconnection keeps server hanging 如何在Java服务器和JavaScript客户端之间使用套接字通信? - How can i use socket communication between java server and javascript client? 如何从客户端检测 Java 套接字断开连接? - How to detect Java socket disconnection from client side? 如何使用 Socket 将客户端连接到 Java 中的服务器 - How can I connect a client to a server in Java using Socket 如何使用Java线程模拟客户端服务器应用程序? - How can I simulate a Client-Server application using Java threads? 我可以使用Cookie或其他一些会话变量来设置客户端和服务器(套接字)之间的会话状态吗? - Can I set the session state between client and server (socket) using a cookie or some other session variable 断开服务器连接后如何在Spring MVC中保持客户端会话有效 - How to keep client session alive in spring MVC after server disconnection 无法在 java 中的 2 台 PC 套接字之间将客户端连接到服务器 - Can't connect client to server between 2 PCs socket in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM