Skip to content

Instantly share code, notes, and snippets.

@johnkchow
johnkchow / em_tcp_message_framing.rb
Created February 21, 2012 21:46
Simple EventMachine TCP messaging framing example
require 'bindata'
module ServerConnection
def receive_data(data)
@buffer ||= []
@data_size ||= 0
@current_size ||= 0
if @buffer.empty?
# First four characters of any framed message will always be the size of message