我想在客户端关闭或丢失的Internet连接和删除是从列表client中检测服务器处的客户的断开连接。我可以做吗?
我正在尝试一些问题,但它不起作用。这是我的代码:
final ChannelFuture cf = chc.channel().writeAndFlush(new TextWebSocketFrame(dataSend));
cf.addListener(new GenericFutureListener<Future<? super Void>>() {
public void operationComplete(Future<? super Void> f) throws Exception {
if (!cf.isSuccess()) {
ServerHandler.agentChannelList.get(tranfer.getUsername()).remove(chc);
if (ServerHandler.agentChannelList.get(tranfer.getUsername()).isEmpty()) {
if (ServerHandler.agentOnlineQueue.containsKey(tranfer.getPage_id())) {
ServerHandler.agentOnlineQueue.get(tranfer.getPage_id()).remove(tranfer.getUsername());
}
}
}
}
});
唯一的"真实"解决方案是在协议中实现类似" ping/pong"之类的东西。基本上,您写信给远程对等方,如果写入失败或远程对等式不响应,您将假定它已死。