[erlang-questions] Line Receiver example?

Oscar Hellström <>
Mon Apr 27 18:37:34 CEST 2009


Hi Jarrod,

I guess what you're looking for is the packet option for sockets. In
case you're using a TCP socket you can either open your listen socket
with the option {packet, line}, gen_tcp:listen(Port, [{packet, line}]),
or you can set it to line based parsing later by issuing
inet:setopts(Socket, [{packet, line}]). In case of UDP you need to open
the socket with gen_upd:open(Port, [{packet, line}]). inet:setopts/2
will also work for a UDP socket.

Jarrod Roberson wrote:
> I am desperately trying to convert the example code from the SHOUTCast
> server example in the Programming Erlang book to call a function on
> every line received instead of the way it works in the book.
> I am coming from using the Twisted framework for Python and trying to
> port some applications, Twisted has a "Line Receiver" protocol that
> calls a function when every line is detected.
> It makes writing basic protocols very easy. I have been unsuccessful
> in trying to accomplish the same thing with Erlang.
> ------------------------------------------------------------------------
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions

Best regards

-- 
Oscar Hellström, 
Office: +44 20 7655 0337
Mobile: +44 798 45 44 773
Erlang Training and Consulting Ltd
http://www.erlang-consulting.com/




More information about the erlang-questions mailing list