File:  [ELWIX - Embedded LightWeight unIX -] / mqtt / example / Attic / cmds.c
Revision 1.1.2.5: download - view: text, annotated - select for diffs - revision graph
Tue Nov 22 10:33:39 2011 UTC (12 years, 8 months ago) by misho
Branches: mqtt1_0
add SUBSCRIBE func

    1: #include <stdio.h>
    2: #include <string.h>
    3: #include <sys/types.h>
    4: #include <aitmqtt.h>
    5: 
    6: 
    7: int
    8: main()
    9: {
   10: 	mqtt_msg_t *m;
   11: 	mqtt_subscr_t s[4];
   12: 	int i;
   13: 
   14: 	m = mqtt_msgAlloc(0);
   15: 	/* conn* */
   16: 	printf("connect=%d/%d\n", m->msg_len, mqtt_msgCONNECT(m, "MRYN", "aaaaa", NULL, "bbb", NULL, 0, 0, 0));
   17: 	for (i = 0; i < m->msg_len; i++)
   18: 		printf("%d\n", ((u_char*) m->msg_base)[i]);
   19: 	printf("connack=%d/%d\n", m->msg_len, mqtt_msgCONNACK(m, 1));
   20: 	for (i = 0; i < m->msg_len; i++)
   21: 		printf("%d\n", ((u_char*) m->msg_base)[i]);
   22: 
   23: 	/* pub* */
   24: 	printf("publish=%d/%d\n", m->msg_len, mqtt_msgPUBLISH(m, "AAA/bbb/CCC/ddd", 7, 0, 2, 0, "OLE!!!", 7));
   25: 	for (i = 0; i < m->msg_len; i++)
   26: 		printf("%d\n", ((u_char*) m->msg_base)[i]);
   27: 	printf("puback=%d/%d\n", m->msg_len, mqtt_msgPUBACK(m, 10));
   28: 	for (i = 0; i < m->msg_len; i++)
   29: 		printf("%d\n", ((u_char*) m->msg_base)[i]);
   30: 	printf("pubrec=%d/%d\n", m->msg_len, mqtt_msgPUBREC(m, 11));
   31: 	for (i = 0; i < m->msg_len; i++)
   32: 		printf("%d\n", ((u_char*) m->msg_base)[i]);
   33: 	printf("pubrel=%d/%d\n", m->msg_len, mqtt_msgPUBREL(m, 12));
   34: 	for (i = 0; i < m->msg_len; i++)
   35: 		printf("%d\n", ((u_char*) m->msg_base)[i]);
   36: 	printf("pubcomp=%d/%d\n", m->msg_len, mqtt_msgPUBCOMP(m, 13));
   37: 	for (i = 0; i < m->msg_len; i++)
   38: 		printf("%d\n", ((u_char*) m->msg_base)[i]);
   39: 
   40: 	/* sub* */
   41: 	memset(s, 0, sizeof s);
   42: 	s[0].sub_sb.sb.l = 3;
   43: 	s[0].sub_data = "a/b";
   44: 	s[0].sub_qos = MQTT_QOS_ACK;
   45: 	s[1].sub_sb.sb.l = 3;
   46: 	s[1].sub_data = "c/d";
   47: 	s[1].sub_qos = MQTT_QOS_ONCE;
   48: 	s[2].sub_sb.sb.l = 7;
   49: 	s[2].sub_data = "x/y/z/Q";
   50: 	s[2].sub_qos = MQTT_QOS_EXACTLY;
   51: 	printf("subscribe=%d/%d\n", m->msg_len, mqtt_msgSUBSCRIBE(m, s, 10, 0, 0));
   52: 	for (i = 0; i < m->msg_len; i++)
   53: 		printf("%d\n", ((u_char*) m->msg_base)[i]);
   54: 
   55: 	mqtt_msgFree(&m, 42);
   56: 	return 0;
   57: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>