Skip to content

Instantly share code, notes, and snippets.

@bokner
Last active December 19, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bokner/5967268 to your computer and use it in GitHub Desktop.
Save bokner/5967268 to your computer and use it in GitHub Desktop.
#!/usr/bin/env escript
main([]) ->
{ok, Client} = gen_client:start("some_user@woow.com", "localhost", 5222, "password"),
%% We can add any number of handlers (callbacks) to the session
%% Message handler
gen_client:add_handler(Client,
fun(#received_packet{packet_type = message, type_attr = "chat", from = Jid}, _Session) ->
io:format("Got message from ~p~n", [Jid]);
(_, _) ->
ok
end,
%% Or, we can send sync packet and wait (more appropriate for IQ requests):
case gen_client:send_sync_packet(Client, exmpp_message:chat("Hi, Bob!"), 1000) of
{ok, #received_packet{packet_type = message}} ->
io:format("Got message:~p~n", [Received]);
timeout ->
io:format("no reply~n");
{error, Reason} ->
io:format("something went wrong: ~p", [Reason])
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment