Bula
Bula

Reputation: 2792

Basic syntax error in erlang

I'm trying to spot the syntax error in the following piece of code however I just can't really see what went wrong. I'm sure it's basic but I just need a fresh pair of eyes on this code:

sloop(Listen)->
    {ok, Socket} = gen_tcp:accept(Listen),
    io:format("Someone connected"),
    master ! {add,Socket},
    spawn(fun() -> sloop(Listen) end),
    receive
        {tcp, Socket, Bin} ->
             case read(Bin) of
                    {join,Channel} -> 
                        tracker ! {self(),get,Socket},
                        receive 
                            void -> 
                                master ! {delete, Socket},
                                A = lists:dropwhile(fun(A) -> A /= Channel end, resgistered()),
                                case A of
                                    [H|T] -> H ! {add,Socket};
                                    _ -> register(Channel,spawn(fun() -> listenerSocket([]) end))
                                end,
                            Channel ! {add, Socket},
                            tracker ! {insert,Socket, Channel};
                            {ok, Value} -> 
                                Value ! {delete,Socket},
                                tracker ! {delete,Socket},
                                A = lists:dropwhile(fun(A) -> A /= Channel end, resgistered()),
                                case A of
                                    [H|T] -> H ! {add,Socket};
                                    _ -> register(Channel,spawn(fun() -> listenerSocket([]) end))
                                end,
                            Channel ! {add, Socket},
                            tracker ! {insert,Socket, Channel};
                    {message, Msg} ->   
                        tracker ! {self(),get,Socket},
                        receive 
                            {ok, Value} -> Value ! {broadcast, Msg}
                        end
             end;
        {tcp_closed, Socket} -> io:format("Someone disconnected")
    end.

Syntax error before "." line 50. Line 50 is the last line in this snippet of code

Upvotes: 0

Views: 59

Answers (1)

Steve Vinoski
Steve Vinoski

Reputation: 20024

You're missing an end. The final end you show matches case read(Bin)..., so you need one more for the enclosing receive.

Upvotes: 1

Related Questions