[erlang-questions] Issue with my first program
Timothy Baldridge
tbaldridge@REDACTED
Thu Sep 4 21:34:19 CEST 2008
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
More information about the erlang-questions
mailing list