GithubHelp home page GithubHelp logo

isabella232 / paho.mqtt.d Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eclipse/paho.mqtt.d

0.0 0.0 0.0 64 KB

Paho library in D

License: Eclipse Public License 1.0

D 98.70% Makefile 1.30%

paho.mqtt.d's Introduction

Eclipse Paho MQTT D client library

This repository contains the source code for the Eclipse Paho MQTT D client library on memory-managed operating systems such as Linux/Posix and Windows.

Note that this library is currenly in an early incubation phase. Although the code is operational, the overall project is lacking in essentials such as a complete implementation, proper documentation, and basic testing.

This code builds a library which enables D applications to connect to an MQTT broker to publish messages, and to subscribe to topics and receive published messages.

Currently only asynchronous modes of operation are supported.

This code requires the Paho C library by Ian Craggs

Building from source

The library uses the D lang build tool, DUB. It can be downloaded from the DUB download page.

Simply clone the package repository and run dub.

$ git clone https://github.com/eclipse/paho.mqtt.d.git
$ cd paho.mqtt.d
$ dub

Example

Sample applications can be found in the samples subdirectory.

int main()
{
	const int QOS = 1;

	try {
		auto cli = new MqttAsyncClient("tcp://localhost:1883", "AsyncClient.d");

		if (!cli.isOK()) {
			writeln("Error creating client.");
			return 1;
		}

		writeln("Connecting...");
		auto connListener = new ConnListener;
		MqttToken tok = cli.connect(null, null, connListener);
		tok.waitForCompletion();
		writeln("...OK");

		writeln("Sending a message...");
		stdout.flush();
		MqttDeliveryToken dtok = cli.publish("hello", "Hello World", QOS, false);
		dtok.waitForCompletion();

		writeln("...OK\nSending another message...");
		auto msg = new MqttMessage("Hi There", QOS);
		dtok = cli.publish("hello", msg);
		dtok.waitForCompletion();

		writeln("...OK\nDisconnecting...");
		stdout.flush();
		tok = cli.disconnect();
		tok.waitForCompletion();
		writeln("OK\nDone");

		return 0;
	}
	catch (MqttException exc) {
		writeln("MQTT Error: ", exc.getReasonCode());
	}

	return 1;
}

The API organization and documentation were adapted from the Paho Java library by Dave Locke. Copyright (c) 2012, IBM Corp

All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html


This code requires the Paho C library by Ian Craggs Copyright (c) 2013 IBM Corp.

All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 and Eclipse Distribution License v1.0 which accompany this distribution.

The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License is available at http://www.eclipse.org/org/documents/edl-v10.php.

paho.mqtt.d's People

Contributors

fpagliughi avatar eclipsewebmaster avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.