gen_tcp:send failing silently

Shawn Pearce <>
Mon Feb 23 02:34:00 CET 2004


I'd try a few things.  First, spawn_link the process rather than just
spawn it.  This way, if it dies, you'll at least get the reason message
send back to you on the console.  One side-effect to be aware of though:
if the shell process has an error (example, you enter "1=2.") you'll
take down the process you are developing.

I use io:format/2 not io:fwrite/2.  Make sure you add a newline in the
pattern:  io:format("BLARG~n", []).  Otherwise you'll get weird looking
output, or it may be delayed.  The runtime error you are getting but
not seeing may be something related to the io:fwrite call, but its
doing an exit, and there's nobody trapping the exit and reporting it
to you.  Use spawn_link like I said above, and at least you'll get the
exit message back on the shell.

Are you sure its matching the regexp?   If it doesn't, you are just
dropping right through...  and would never see BLARG get sent out.

 wrote:
> Hi all,
> 
> 	This weekend, I enjoy some recreational programming with Erlang.  I've
> decided to make a "proof-of-Erlang-goodness" IRC bot to show someone.
> 
> 	It's been months since I wrote my last Erlang code and my lack of
> experience is showing:
> 
> connection_handle_data(Socket, [Data | R]) ->
>     % Handles PING
>     case regexp:match(Data, "PING :[0-9].*") of
> 	{match, _, _} ->
> 	    Ping_String = string:substring(Data, 6, 16),
> 	    ok = gen_tcp:send(Socket, io_lib:format("PONG ~s~n", [Ping_String])),
> 	    io:fwrite("BLARG", []);
> 	nomatch ->
> 	    ok
>     end,
>     factron_translator ! {incoming, Data},
>     connection_handle_data(Socket, R);
> connection_handle_data(Socket, []) ->
>     ok.
> 
> 	This function is supposed to handle the PING message but the process
> silently terminates after gen_tcp:send.  "BLARG" is never displayed.  I've
> tried all I knew to try to get a clue on the failure, I'm probably missing
> some debugging techniques.
> 
> 	Also, why is that when I write, for example, io:fwrite() in a process, I
> get a compiler warning, but absolutely no runtime error?  The process just
> seem to go *ZAP* and die :(

-- 
Shawn.

  That does not compute.



More information about the erlang-questions mailing list