如何检测之前连接的 SSL/TCP 套接字上的互联网断开连接? [英] How to detect internet disconnection on SSL/TCP sockets which were connected before?

查看:55
本文介绍了如何检测之前连接的 SSL/TCP 套接字上的互联网断开连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个线程阻塞基于 select()SSL_read().主线程在需要时使用 SSL_write() 写入.在单元测试中,我发现了一个问题:

I am having a thread which blocks on select() based SSL_read(). The main thread writes whenever needed using SSL_write(). During unit testing, I found a problem:

  • 客户端 TCP 套接字 connect() 到 SSL(TLS) 上的服务器
  • 一段时间后,禁用互联网
  • 在客户端 TCP/SSL 套接字上写入一些数据
  • Client TCP socket connect() to server on SSL(TLS)
  • After sometime, disable internet
  • Write some data on client TCP/SSL socket

即使没有互联网,SSL_write() 也会返回正确的写入字节数,而不是 0 或一些错误.这种互联网断开是任意的,既不太高也不太低.

Even without interenet, the SSL_write() returns the correct number of bytes written, instead of 0 or some error. Such interenet disconnections are arbitrary, neither too high nor too low.

我的期望是,每当互联网断开连接时,套接字应该生成一些有趣的事件,这是可检测的,我将中断套接字 + SSL 连接.
如果我必须建立一些客户端 - 服务器手工协议,那么这是可能的.

My expectation is that, whenever there is an internet disconnection, the socket should generate some interesting event, which is detectable and I will discontinue the socket + SSL connections.
In case I have to establish some client-server hand made protocol, then that's possible.

实现此类互联网检测的最佳方法是什么?
期待具有更少 CPU 周期的解决方案 &较小的客户端服务器通信.我敢肯定,这不是一个非常特殊的问题,因此之前肯定已经解决了.

What is the best way to achieve such internet detection?
Expecting a solution with lesser CPU cycles & lesser client server communication. I am sure that, this is not a very special problem and hence must have been solved before.

[P.S.: 客户端套接字是在 Android & 等移动平台上打开的.iOS,但是我想知道一个通​​用的解决方案.]

[P.S.: The client sockets are opened on mobile platforms like Android & iOS, however I would like to know a general solution.]

推荐答案

这是套接字的一般问题.您不能与他们一起提供经过认证的交付.如果您想知道交易对手是否确实可以访问,您必须自己实现某种类型的心跳.

This is general problem with sockets. You can't have a certified delivery with them. If you want to know if the counterparty is indeed reachable, you have to implement some sort of hearbeats yourself.

通常,成功写入套接字并不表示另一端的接收者可用.

Generally successful write to the socket is no indication of availability of the recepient on the other end.

这篇关于如何检测之前连接的 SSL/TCP 套接字上的互联网断开连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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