-module(xmppclient). -export([send/2]). -include_lib("xmerl/include/xmerl.hrl"). % roughed in function to extract text from an xmerl data structure export_text([Head|Rest]) -> [export_text(Head) | export_text(Rest)]; export_text({_Name, _Attrs, Children}) -> export_text(Children); export_text(Other) -> Other. send(Resource, Message) -> % server Host = "rubix", Port = 5223, % source Username = "rubys", Password = "password", % destination To = "rubys@rubix", % XMPP stream Stream = {'stream:stream',[ {'xmlns:stream',"http://etherx.jabber.org/streams"}, {to, Host}, {xmlns, "jabber:client"}], [ {iq, [ {type, "set"}, {id, "auth"}], [ {'query',[ {xmlns, "jabber:iq:auth"}], [ {username, [Username]}, {password, [Password]}, {resource, [Resource]} ] } ] }, {message, [ {to, To}], [ {body,[export_text(Message)]}, % fallback {html,[ % XHTML-IM {xmlns, 'http://jabber.org/protocol/xhtml-im'}], [ {body,[ {xmlns, 'http://www.w3.org/1999/xhtml'}], Message } ] } ] } ] }, % uncomment for debugging % Export = xmerl:export_simple([Session],xmerl_xml), % io:format("~s~n", [xmerl_ucs:to_utf8(Export)]), % do the deed application:start(ssl), {ok, Socket} = ssl:connect(Host, Port, []), ssl:send(Socket, xmerl_ucs:to_utf8(xmerl:export_simple([Stream],xmerl_xml))), ssl:close(Socket).