0

I write a peer-to-peer messenger. After the two peers have established a connection, they want to know whether the other has sent him a message. If not, it sends a message itself. So I need a function that tells me how many bytes are still to be read on the socket. I looked in the documentation, but didn't find it.

When I was just asking the question I was redirected to Ruby TCPSocket: Find out how much data is available. However, I use an SSL socket and it doesn't seem to have .ready?.

Does anyone know a version of the function for the SSLSocket?

I would be very happy about answers!

Marek Küthe
  • 90
  • 1
  • 8
  • 1
    There's no such capability with stream sockets in general, nor with TCP. The best you can do is find out how many bytes are available *right now* in the local socket buffer. However, with SSL/TLS things are different. For security purposes TLS does things on a record-by-record basis. The TLS layer won't return any data at all until it has received a complete record from its peer. Then, it will make the decrypted record available. However, there's no guarantee that a TLS record maps to a "message" in any meaningful way. So, you need to define your own protocol on top of TLS, just as with TCP. – President James K. Polk Oct 07 '21 at 16:21
  • How to find out how many bytes are not yet read in the localbuffer at the SSLSocket? – Marek Küthe Oct 08 '21 at 09:43
  • [the `pending` method](https://ruby-doc.org/stdlib-3.0.2/libdoc/openssl/rdoc/OpenSSL/SSL/SSLSocket.html#method-i-pending) – President James K. Polk Oct 08 '21 at 13:17

0 Answers0