Prepare for OOP Game project.
This project build by Paho Esclipce library - a library support mqtt in many of language.
Create a Maven project by IntelliJ IDEA. Add these line to pom.xml file.
<dependencies>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>Eclipse Paho Repo</id>
<url>https://repo.eclipse.org/content/repositories/paho-releases/</url>
</repository>
</repositories>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Reset the application then the library is installed.
Paho Esclipce support to use tcp or ssl protocol to setup broker. Example: "tcp://hcmiuiot.tech:1883"
Sub.java: subscribe function => subscribe message by a topic and a broker.
Sub testSubClient = new Sub("hcmiuiot.tech", "id/test");
testSubClient.subCore();
Add this code to main class => testSubClient.subCore() subscribes topic: "id/test" by broker: "tcp://hcmiuiot.tech:1883". (The tcp and port 1883 just can be changed in Sub.java)
Pub.java: publish function => publish message to a topic by a broker.
Pub testPubClient = new Pub("hcmiuiot.tech","id/test", "Msg from Kuerl!");
tesPubClient.pubCore();
Add this code to main class => testPubClient.pubCore() publish message to topic: "id/test" by broker: "tcp://hcmiuiot.tech:1883". (The tcp and port 1883 just can be changed in Pub.java)
Broker: "tcp://hcmiuiot.tech:1883" belongs to HCMIU - IOT club.
Just sub, pub at hcmiuiotclub github :vv