gen_tcp:send failing silently
Samuel Tardieu
sam@REDACTED
Mon Feb 23 02:06:21 CET 2004
On 22/02, fgonthier@REDACTED wrote:
| This weekend, I enjoy some recreational programming with Erlang. I've
| decided to make a "proof-of-Erlang-goodness" IRC bot to show someone.
Good idea.
If you're willing to see one that I've been developing using OTP, tell
me and I'll post the code somewhere (it's work in progress, I didn't want
to reuse an old one I had written some years ago).
| connection_handle_data(Socket, [Data | R]) ->
| % Handles PING
| case regexp:match(Data, "PING :[0-9].*") of
This is overkill, you should just compare the beginning to "PING " and
answer with "PONG " and the rest of the string.
| ok = gen_tcp:send(Socket, io_lib:format("PONG ~s~n", [Ping_String])),
You do not need to "prepare" the string yourself. You can send a list
using gen_tcp:send/2, it will be flattened for you. In your example, that
would be something like:
ok = gen_tcp:send (Socket, ["PONG ", Ping_String, "\r\n"])
| io:fwrite("BLARG", []);
Or simply: io:write ("BLARG~n") (I assume you miss a ~n here).
| 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.
Are you sure it gets never displayed? Isn't it caused by the missing ~n?
| 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 :(
What compiler warning?
Sam
More information about the erlang-questions
mailing list