#include "global.h" #include "mqtt.h" int InitClient(void) { int sock; sock = socket(args->addr.sa.sa_family, SOCK_STREAM, IPPROTO_TCP); if (sock == -1) { printf("Error:: socket() #%d - %s\n", errno, strerror(errno)); return -1; } if (connect(sock, &args->addr.sa, args->addr.sa.sa_len) == -1) { printf("Error:: connect() #%d - %s\n", errno, strerror(errno)); return -1; } return sock; } int try2Connect(int sock) { int siz = 0; siz = mqtt_msgCONNECT(args->msg, AIT_GET_STR(&args->ConnID), args->ka, AIT_GET_STR(&args->User), AIT_GET_STR(&args->Pass), args->Will.Topic.val.string, args->Will.Msg.val.string, !args->notClear, args->QoS, args->Retain); if (siz == -1) { printf("Error:: msgCONNECT #%d - %s\n", mqtt_GetErrno(), mqtt_GetError()); return -1; } siz = send(sock, args->msg->msg_base, siz, 0); if (siz == -1) { printf("Error:: send() #%d - %s\n", errno, strerror(errno)); return -1; } else VERB(3) printf("Sended CONNECT %d bytes\n", siz); register int i; for (i = 0; i < siz; i++) printf("%02x ", ((u_char*)args->msg->msg_base)[i]); printf("\n"); return siz; }