Skip to content

Instantly share code, notes, and snippets.

@asanghi
Created August 17, 2012 08:52
Show Gist options
  • Save asanghi/3377119 to your computer and use it in GitHub Desktop.
Save asanghi/3377119 to your computer and use it in GitHub Desktop.
Celluloid IO connection handler
def read_until_eot(socket)
eot_found = false
message = ''
begin
message += socket.read()
eot_found = message['\004'].present? # <-- ughh what can i do?
end until eot_found
message
end
def handle_connection(socket)
# read from socket until EOT
message = read_until_eot(socket) # <-- need help with
if parse(message) #message can be parsed
# process message
output = process(message)
end
# write to socket
socket.write output_message
# close socket
socket.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment