You might want to use LineProtocol to simplify this. Also it'll flush for you !
http://eventmachine.rubyforge.org/EventMachine/Protocols/LineProtocol.html