Created
June 17, 2010 06:50
-
-
Save sidonath/441768 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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