In fact, using gen_tcp:recv is a bad idea for a "rock solid" server, because you will not be able to stop process or reload its code. Proper way is to inet:setops(Socket, [{active,once}]), use buffer and use erlang:decode_packet to decode lines