I have a custom Protobuf-based protocol that I've implemented as an EventMachine protocol and I'd like to use it over a secure connection between the server and clients. Each time I send a message from a client to the server, I prepend the message with a 4-byte integer representing the size of the Protobuf serialized string to be sent such that the server knows how many bytes to read off the wire before parsing the data back into a Protobuf message.
I'm calling
start_tlsin thepost_initcallback method in both the client and server protocol handlers, with the one in the server handler being passed the server's private key and certificate. There seems to be no errors happening at this stage, based on log messages I'm printing out.Where I get into trouble is when I begin parsing data in the
receive_datacallback in the server's handler code... I read 4 bytes of data off the wire and unpack it to an integer, but the integer that gets unpacked is not the same integer I send from the client (i.e. I'm sending 17, but receiving 134222349).Note that this does not happen when I don't use TLS... everything works fine if I remove the
start_tlscalls in both the client and server code.Is it the case that SSL/TLS data gets passed to the
receive_datacallback when TLS is used? If so, how do I know when data from the client begins? I can't seem to find any example code that discusses this use case...