Parsing an incoming Shoutcast request

Thomas Lindgren thomasl_erlang@REDACTED
Mon May 29 16:38:54 CEST 2006

--- Andrew Lentvorski <bsder@REDACTED> wrote:

> Another newbie question.
> I'm trying to do something very similar to the
> Shoutcast server sample 
> code from Practical Common Lisp.  The initial
> request from an MP3 client 
> to the streaming server (which I want to write in
> Erlang) looks very 
> much like HTTP.
> GET / HTTP/1.1\r\n
> Host:\r\n
> User-Agent: VLC media player - version 0.8.5 Janus -
> VideoLAN team\r\n
> Range: bytes=0-\r\n
> Icy-MetaData: 1\r\n
> Connection: Close\r\n
> \r\n
> Now, I know have to do the gen_tcp:listen and
> gen_tcp:accept to get the 
> actual connection socket.
> Once, I have that socket, though, I either need to
> do something with 
> messages and {active, once} or gen_tcp:recv() and
> {active, false}.
> I can't see a particularly obvious way to structure
> this for pattern 
> matches to make things easy.

Start with setting the socket in {packet,line} mode,
which delivers messages in units of "lines". See "man
inet" for details.

You can then match on each incoming line, something
like this (OK, I haven't checked that this actually
works, but the principle should be clear):

match_header_line(<<"\r\n">>, State) ->
match_header_line(<<"User agent:", Name/binary>>,
State) ->
   add_user_agent(Name, State);

Alternatively, and even simpler: if the protocol is
close enough to HTTP, there is the semi-secret
{packet, http} mode.


Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

More information about the erlang-questions mailing list