Last active
December 19, 2015 14:09
-
-
Save bokner/5967268 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env escript | |
main([]) -> | |
{ok, Client} = gen_client:start("[email protected]", "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