Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8988507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:01:19+00:00 2026-06-15T22:01:19+00:00

I have a custom Protobuf-based protocol that I’ve implemented as an EventMachine protocol and

  • 0

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_tls in the post_init callback 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_data callback 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_tls calls in both the client and server code.

Is it the case that SSL/TLS data gets passed to the receive_data callback 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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:01:20+00:00Added an answer on June 15, 2026 at 10:01 pm

    OK, so via a cross-post to the EventMachine Google Group I figured out what my problem was here. Essentially, I was trying to send data from the client to the server before the TLS handshake was done because I wasn’t waiting until the ssl_handshake_completed callback was called.

    Here’s the code I got to work, just in case anyone comes across this post in the future. 🙂

    Handler code for the server-side:

    require 'eventmachine'
    
    class ServerHandler < EM::Connection
      def post_init
        start_tls :private_key_file => 'server.key', :cert_chain_file => 'server.crt', :verify_peer => false
      end
    
      def receive_data(data)
        puts "Received data in server: #{data}"
        send_data(data)
      end
    end
    

    Handler code for the client-side:

    require 'eventmachine'
    
    class ClientHandler < EM::Connection
      def connection_completed
        start_tls
      end
    
      def receive_data(data)
        puts "Received data in client: #{data}"
      end
    
      def ssl_handshake_completed
        send_data('Hello World! - 12345')
      end
    end
    

    Code to start server:

    EventMachine.run do
      puts 'Starting server...'
      EventMachine.start_server('127.0.0.1', 45123, ServerHandler)
    end
    

    Code to start client:

    EventMachine.run do                      
      puts 'Starting client...'              
      EventMachine.connect('127.0.0.1', 45123, ClientHandler)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have custom event that has several different subscribers who will all use the
I have custom radar tiles that I am trying to overlay over Google Maps
I have custom slider that I use the following touch event to respond to:
I have custom SPlist with some fields that I'd like to bind to a
I have custom checkstyle checks file (called checks.xml), and I'm trying to use that
I have custom validators and filters that I have created that I would like
I have custom button, with an image that I'd like to shift down within
I have custom classes that I currently instantiate within App.xaml as resources. I want
I have custom gallery. Gallery represents items that are frame layout. There are one
I have custom component that I can place in my layout file (XML) for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.