Home modules.gotpike.org
Username: Password: [Create Account]
[Forgot Password?]

Modules

ADT
Database
GTK2
GUI
IP
PiJAX
Public
Sql
Stdio
Subversion
System
Tools
Xosd
lua
v4l2
wx

Recent Changes

Public.Parser.XML2 1.50
Public.ZeroMQ 1.1
Public.Template.Mustache 1.0
Public.Protocols.XMPP 1.4
Sql.Provider.jdbc 1.0

Popular Downloads

Public.Parser.JSON2 1.0
Public.Parser.JSON 0.2
GTK2 2.23
Public.Web.FCGI 1.8
Public.Parser.XML2 1.48


Module Information
Public.Protocols.MQTT
Viewing contents of Public_Protocols_MQTT-1.2/test.pike


object p;

int main() {

  p = Public.Protocols.MQTT.client("mqtts://37.187.106.16");
  p->set_client_identifier("hww3-" + time());
  p->set_disconnect_callback(dis_cb);
  werror("Client: %O\n", p);
  p->connect(has_connected);
  werror("Client: %O\n", p);
 return -1;

}

void has_connected(object client) {
	werror("Client connected: %O\n", client);
	client->set_qos_level(2);
	client->subscribe("hww3/test", pub_cb);
	client->publish("hww3/test", "client_connect" * 20, 2);
}

int c = 0;
void pub_cb(object client, string topic, string body) {
	c ++;
	werror("Received message: %O, %s -> %O\n", client, topic, body);

	if(c > 2) {
  	client->unsubscribe(topic, pub_cb);
	client->disconnect();
  }
}

void dis_cb(object client, object reason) {
	werror("Client disconnected: %O=>%O\n", client, reason);
}


gotpike.org | Copyright © 2004 - 2019 | Pike is a trademark of Department of Computer and Information Science, Linköping University