[erlang-questions] Issue with my first program
Edwin Fine
erlang-questions_efine@REDACTED
Thu Sep 4 21:55:22 CEST 2008
dispatchloop is expecting a list but you are giving it a binary.
You probably want something like
dispatchloop(<<>>, Working) ->
Working;
dispatchloop(<<$#,Rest/bytes>>, Working) ->
callcommand(Working),
dispatchloop(Rest, []);
dispatchloop(<<_Skip,Rest/bytes>>, Working) ->
dispatchloop(Rest, Working).
HTH
On Thu, Sep 4, 2008 at 3:34 PM, Timothy Baldridge <tbaldridge@REDACTED>wrote:
> Well, I'm finally making the dive into Erlang programming. I have
> project at work here that I'm using to learn with. Basically this
> program will connect to a tcp server. Then it will begin to parse info
> that the server spits out. The data is in this format (plaintext):
>
> command|arg1|arg2#command2|arg2#
>
> So # separates commands and | separates phrases. Here's the code I have so
> far:
>
> -module(filemonitor).
> -export([start/1, dispatchloop/2]).
>
> start(Ip) ->
> {ok, Socket} = gen_tcp:connect(Ip, 9442, [binary]),
> loop(Socket, []).
>
> loop(Socket, Buffer) ->
> receive
> {tcp, Socket, Bin} ->
> io:format("~p~n", [Bin]),
> Newbuff = dispatchloop(Bin, Buffer),
> loop(Socket, Newbuff);
> {tcp_error, Socket, Reason} ->
> io:format("Error ~p~n", [Reason]),
> gen_tcp:close(Socket);
> {tcp_closed, Socket} ->
> io:format("Connection Terminated~n")
> end.
>
>
>
> callcommand(Working) ->
> io:format("~s~n", [Working]).
>
> dispatchloop([],Working) ->
> Working;
> dispatchloop([H|T], Working) ->
> if
> H == "#" ->
> callcommand(Working),
> dispatchloop(T, []);
> true ->
> dispatchloop(T, Working)
> end.
>
>
> I get this error:
>
> 4> filemonitor:start("192.168.101.170").
> <<"getattr|/#">>
> ** exception exit: function_clause
> in function filemonitor:dispatchloop/2
> called as filemonitor:dispatchloop(<<"getattr|/#">>,[])
> in call from filemonitor:loop/2
>
>
> Any ideas I'm stumped....
>
> Thanks,
>
> Timothy
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080904/2a598b6c/attachment.htm>
More information about the erlang-questions
mailing list