在Java中从客户端重新连接到服务器 [英] Reconnecting to server from client in java

查看:202
本文介绍了在Java中从客户端重新连接到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个用于将客户端连接到服务器以捕获客户端屏幕的程序.在该客户端中,会将其桌面屏幕发送到服务器.当我关闭服务器时,客户端的屏幕截图将运行.我的问题是,当我关闭时,我希望客户端关闭连接并重新打开用于连接服务器的套接字.如果您需要代码,我会发布,但是由于摇摆应用程序,它有点大.如果您需要我可以发布代码.给我这个问题的解决方案.

I have written a program for connecting client to server for capturing client screen. In that client will send their desktop screen to server. When i close the server client screen capture will be running . My problem is when i close i want the client to close the connection and reopen the socket for connecting to server. If you need the code i will post but it is little bit big because of swing application . if you need i can post the code. Give me any solution for this problem.

推荐答案

问题出在哪里?您的客户端应从服务器检索强制客户端关闭连接并打开一个新命令以侦听新服务器连接的最后一条命令.服务器重新启动后,它将通知客户端并重新建立连接.

您也可以强制客户端尝试不时连接,直到成功为止.有点棘手的原因是您需要在此期间静默捕获异常.
Where is the problem? your client should retrieve from the server the last command that is forcing the clients to close the connection and open a new one to listen for new server connections. When the server comes back on, it will notify the client and the connection is established again.

You could also force the client to try to connect from time to time until it succeeds. A little tricky cause you need to catch the exceptions silently during this.


这篇关于在Java中从客户端重新连接到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆