-module(jabberdemo). -export([main/0]). -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. main() -> % server Host = "rubix", Port = 5223, % from Username = "rubys", Password = "password", Resource = "erlangDemo", % message To = "rubys@rubix", Link = "http://www.erlang.org/", Message = ["Hello <", {a, [{href,Link}], ["Erlang"]}, "> world!"], % XMPP stream Session = {'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 out for debugging % io:format("~s~n", [xmerl:export_simple([Session],xmerl_xml)]), % do the deed application:start(ssl), {ok, Socket} = ssl:connect(Host, Port, []), ssl:send(Socket, xmerl:export_simple([Session],xmerl_xml)), ssl:close(Socket).