libstrophe简单介绍
作者:shj 发布于:2014-4-14 15:05
打算搞个XMPP的通信工具。俺搞就是个写C的,JAVA那么高大尚的俺不懂。只有找个C库方便移植的来用了。
初步选了下,选用libstrophe。但在网上找了半天没找到个中文的简单介绍。我就来写个算了。
先说下初始化:
xmpp_ctx_t *ctx = NULL;
xmpp_log_t *log;
char jid[256]={"test1@jz"};
/* take a jid and password on the command line */
/*jid=username@host*/
xmpp_initialize();
log = xmpp_get_default_logger(XMPP_LEVEL_ERROR); /* pass NULL instead to silence output */
ctx = xmpp_ctx_new(NULL, log);
conn = xmpp_conn_new(ctx);
/* setup authentication information */
xmpp_conn_set_jid(conn, jid);
xmpp_conn_set_pass(conn, "test1");
/* initiate connection */
xmpp_connect_client(conn, "shjpnn.com", 5222, conn_handler, ctx);
jid里需要注意,是用户名@域。XMPP服务器是要区分域的。如果不知道。。。就先看下这个在说。
ctx就当他是个标示吧。反正到处都在用。conn_handler是给libstrophe用的一个回调函数。在里面需要注册一些你关心的东西。
上面的完成之后需要的是xmpp_run(ctx);这里xmpp_run是一个阻塞的调用。之后收到消息都在 conn_handler里注册的回调。
先写这几句之后的空了写。
评论:


2014-07-28 19:20