Skip to content

Instantly share code, notes, and snippets.

@sidonath
Created June 17, 2010 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidonath/441768 to your computer and use it in GitHub Desktop.
Save sidonath/441768 to your computer and use it in GitHub Desktop.
# Strip leading and trailing bytes
def self.decode data, &blk
while msg = data.slice!(/\000([^\377]*)\377/)
msg.gsub!(/^\x00|\xff$/, '')
yield msg
end
end
# when the connection receives data from the client
# we either handshake or handle the message at
# the app layer
def receive_data data
unless @connected
handshake data
else
Frame.decode(data) { |msg| on_receive msg }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment