如何模拟套接字断开连接?

发布于 2024-12-04 11:02:35 字数 148 浏览 1 评论 0原文

我的应用程序将文件上传到客户端的服务器,但他想要特殊的“暂停上传”功能。我不能简单地关闭连接,甚至不能终止进程 - 他需要失去连接,否则他的服务器应用程序会删除未完成的文件 - 所以我必须在代码“电缆拔出”中模拟 - 你有什么建议吗? 感谢您的帮助,并对我的英语表示抱歉:) 吉尔卡

My application uploads files to server of my client, but he want special "pause upload" function. I cant simply close connection, not even kill process - he need to lost connection otherwise his server application delete unfinished file - so i have to simulate in code "cable unplug" - do you have any suggestion?
thanks for your help and sorry for my english :)
jirka

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青春有你 2024-12-11 11:02:35

您可以使用 Mockito 为您的设备创建 Socket 模拟测试,如这个问题所建议的:测试 Java 套接字

You can use Mockito to create a Socket mock for your unit tests, as suggested on this question: Testing Java Sockets

夜深人未静 2024-12-11 11:02:35

如果您同时编写了客户端和服务器,也许更好的选择是发送一些 OOB 数据 告诉服务器您正在暂停(或者一条消息告诉服务器不要在下一次套接字关闭时删除文件)。通常最好是明确的,而不是依赖某些操作的副作用 - 在您的情况下,关闭套接字而不明确 连接终止

If you wrote both the client and the server, maybe the better option is to send some OOB data to tell the server that you are pausing (or a message to tell the server to not delete the file on next socket close). It is usually better to be explicit instead of relying on side effects of certain actions - in your case, closing a socket without explicit connection termination.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文