Кто-нибудь хорош в отладке Erlang? Я не могу понять для себя, что случилось. Куда бы я ни поместил переменную Fields, Эрланг говорит, что перед этой строкой есть ошибка ...
Скомпилировать сообщения:
./eventbus.erl:6: syntax error before: FieldPositions
./eventbus.erl:24: variable 'FieldPositions' is unbound
./eventbus.erl:28: Warning: variable 'Ref' is unused
./eventbus.erl:30: Warning: variable 'List' is unused
error
А потом сам код.
-module(secret).
-export([listen/1, send/1]).
-define(TCP_OPTIONS, [binary, {packet, 0}, {active, false}, {reuseaddr, true}]).
FieldPositions = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","AA","BB","CC","DD","EE","FF","GG","HH","II","JJ","KK","LL","MM","NN","OO","PP"].
listen(Port) ->
{ok, LSocket} = gen_tcp:listen(Port, ?TCP_OPTIONS),
accept(LSocket).
accept(LSocket) ->
{ok, Socket} = gen_tcp:accept(LSocket),
spawn(fun() -> loop(Socket) end),
accept(LSocket).
discrim(<<>>) ->
ok;
discrim([]) ->
ok;
discrim(Info) ->
EventsList = string:tokens(Info,"|"),
process_events(EventsList, FieldPositions).
process_events([],[]) ->
ok;
process_events([],Ref) ->
ok;
process_events(List,[]) ->
ok;
process_events(List,Ref) ->
[RHead|RTail] = Ref,
[Head|Tail] = List,
if
Head == [] ->
process_events(Tail, RTail);
true ->
io:format("message.bus ~s ~s",[RHead,Head]),
process_events(Tail, RTail),
ok
end.
loop(Socket) ->
case gen_tcp:recv(Socket, 0) of
{ok, Data} ->
%gen_tcp:send(Socket, Data),
%io:format(Data),
discrim(Data),
io:format("~n"),
loop(Socket);
{error, closed} ->
ok
end.