<div dir="ltr">Hi,<br>
<br>
The function given as an argument to spawn/spawn_link must be exported.<br>
<br>See e.g. <a href="http://erlang.org/doc/getting_started/conc_prog.html#3.1">http://erlang.org/doc/getting_started/conc_prog.html#3.1</a><br><br>
BR /Fredrik<br><br><br><div class="gmail_quote">On Sun, Oct 5, 2008 at 6:39 PM, deepblue_other <span dir="ltr"><<a href="mailto:cktgatb@gmail.com">cktgatb@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Hello, its me again...<br>
so I've been having this problem for days, with the bellow code. Most of it<br>
is straight out of the "Programming Erlang" book from Joe Armstrong...<br>
however when Im compiling it its telling me that the function data_process/1<br>
is not being used, gives me a warning, but then still compiles. however when<br>
Im sending data from a client side via TCP ofcourse it exits on me because<br>
there's nothing to process the message...<br>
<br>
I HAVE NO IDEA WHAT'S WRONG WITH IT.<br>
I've read up on all the spawn_link() definitions and as far as I can tell Im<br>
using it correctly... the PiD that spawn_link() returns is being returned so<br>
it executes successfully.<br>
please help out, its stalling my project progress.<br>
thanks<br>
<br>
<br>
-module(tcp_manager).<br>
%API--------------------------------------------<br>
-export([start/1]).<br>
%-----------------------------------------------<br>
start(Port) -><br>
{ok, ListeningSocket} =<br>
gen_tcp:listen( Port, [ binary, %receive data in binary form<br>
{packet , 0},<br>
{reuseaddr, true},<br>
%hybrid - active for only one message<br>
%it auto-receives one message after<br>
which it blocks<br>
%has to be set to active-once again to<br>
receive the next message<br>
{active , once} ] ),<br>
accept_connection(ListeningSocket).<br>
%-----------------------------------------------<br>
accept_connection(ListeningSocket) -><br>
<br>
io:format("waiting to accept~n"),<br>
{ok, Socket} = gen_tcp:accept(ListeningSocket),<br>
io:format("Socket is:~p~n", [Socket]),<br>
<br>
%-----------------------------------------------<br>
Listen_for_errors =<br>
fun() -><br>
io:format("listening started~n"),<br>
receive<br>
{'EXIT', Pid, Why} -><br>
io:format("~p exited because:~p", [Pid,Why]);<br>
Other -><br>
io:format("Other:~p~n", [Other])<br>
end<br>
end,<br>
Listen_for_errors(),<br>
%-----------------------------------------------<br>
<br>
Handler_process = spawn_link(?MODULE, data_process, [Socket]), %,[]]),<br>
io:format("handlers process ID:~p", [Handler_process]).<br>
<br>
accept_connection(ListeningSocket).<br>
%-----------------------------------------------<br>
data_process( Socket, DataSoFar) -><br>
io:format("responder_loop() entered~n"),<br>
<br>
receive<br>
{tcp, Socket, Data} -><br>
%Source_ip = inet:peername(Socket),<br>
%io:format("*~p - data coming in:~p~n",[Source_ip,Data]),<br>
io:format("works - Data:~p~n", [Data]),<br>
%has to be done, since its an active-once socket<br>
inet:setopts( Socket, [{active,once}] ),<br>
data_process( Socket,<br>
%append the new binary fragment to what has<br>
been received so far<br>
[Data | DataSoFar] );<br>
<br>
{tcp_closed, Socket} -><br>
io:format("*client socket closed~n");<br>
%reverse because data has been appended to the head of the list<br>
as it was coming in<br>
list_to_binary(lists:reverse(SoFar));<br>
Other -><br>
io:format("undefined message came in:~p", [Other])<br>
end.<br>
%-----------------------------------------------<br>
<font color="#888888">--<br>
View this message in context: <a href="http://www.nabble.com/wierd-%22function-not-used%22-problem---code-included-tp19826465p19826465.html" target="_blank">http://www.nabble.com/wierd-%22function-not-used%22-problem---code-included-tp19826465p19826465.html</a><br>
Sent from the Erlang Questions mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
</font></blockquote></div><br></div>