[erlang-questions] Switching between http/non-http depending of first byte
Tony Rogvall
tony@REDACTED
Thu Oct 1 21:54:48 CEST 2009
Try using:
gen_tcp:unrecv(S, Data).
On accepting side you should have the listen socket in passive mode
[{active,false},{packet,0}], then:
{ok,S} = gen_tcp:accept(L).
case gen_tcp:recv(S, 1) of
{ok,[3]} ->
gen_tcp:unrecv(S, [3]),
rtmp_handler(S);
{ok,H} ->
gen_tcp:unrecv(S, H),
%% switch to http protocol ..
http_handler(S)
Error ->
...
end.
/Tony
On 1 okt 2009, at 09.50, Max Lapshin wrote:
> Hi. I want to implement an unusual feature: when server accepts
> socket,
> it must look at first byte. If it is 0x03, than I want to handle it by
> one handler (RTMP),
> if other, than HTTP handler.
>
> Problem is that I need only one byte and received packet should be
> passed to exact protocol handler.
>
> I understand, that I will not be able to use erlang setopt(http)
> feature, so question is the following:
>
> should I better use Yaws or MochiWeb as underlying webserver?
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
More information about the erlang-questions
mailing list