B4A Library MQTT Multiplayer Library

This is a MQTT Multiplayer Library created by one of the best B4A library creators and member in the B4X Community. I use his libraries in all of my games. I didn’t write any of this code and I told him I would keep his identity private unless he wanted to reveal who he is.

I use it to play a Multiplayer card game with an Android and iOS device. I couldn’t find a better way for and Android player to play and iPhone player. I uploaded the Broker.jar to my Linux Virtual Private Server. I send a list from B4a and a NSMutableArray (NSArray) from Xcode in Objective C.

I used the following pods to install the library on my iOS devices.
pod 'MQTTClient/MinL'
pod 'MQTTClient/ManagerL'
pod 'MQTTClient/WebsocketL'


Here is the explanation on how to use the library.

Step by step to try the demos:
- download the archive and copy the content of Lib to the directory of additional libraries of B4J;
- set a valid port number in Broker/Broker. b4j (line 10);
- open this port on your server, if necessary;
- compile the Broker.b4j project;
- upload the result (Broker.jar) on your server and execute it;
- in the two projects under Demo_Clients, enter the IP address of the server and the port used by the broker (B4A: lines 28 and 29; B4J: lines 19 and 20);
- in the Client.b4a project, you can change the method of identification of the device line 48 (the goal is that the device is identified with an unique ID; the demo code will work but that won’t be the case in a real application with many users because some devices share the same android_id);
- in the Client.b4j project, you can also change the ClientID and put whatever you want;
- run the clients and click on the Connect button.

I've used this for 2 years and it works perfectly so far. Feel free to use this however you like. B4J has been updated a few times since then so I hope this still compiles. I'm the worst programmer so I can't be of much help to anyone but I will answer what I can.
 

Attachments

  • jMQTTBrokerExtended.jar
    5.3 KB · Views: 502
  • jMQTTBrokerExtended.xml
    3.7 KB · Views: 512
  • Broker.zip
    3.3 KB · Views: 523
  • Demo_Clients.zip
    15 KB · Views: 495
  • Lib_Source.zip
    5.2 KB · Views: 559
  • jMQTTBrokerExtended.zip
    6.1 KB · Views: 529

Sia Kong Lam

Member
Licensed User
Longtime User
Hi @paris7162,

Thanks for sharing.
While compiling Broker.b4j the following error msg displayed, Cannot find 'moquette8.jar'. Where to download this jar? and any help will be much appreciated.
1588709631804.png

Regards,
Sia
 

ilan

Expert
Licensed User
Longtime User
wow, thank you for sharing. can you post links of some of your games you made with this library?

thanx
 

Sia Kong Lam

Member
Licensed User
Longtime User
Thanks for the help ilan & Domanfred. I did try all the moquette-broker from the link as suggested (tq).
When compiled, the following log displays....

main._process_globals (java line: 288)
java.lang.NoClassDefFoundError: io/moquette/server/config/IConfig
at b4j.example.main._process_globals(main.java:288)
at b4j.example.main.initializeProcessGlobals(main.java:279)
at b4j.example.main.main(main.java:27)
Caused by: java.lang.ClassNotFoundException: io.moquette.server.config.IConfig
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more

downloaded files changed from moquette-broker-0.??.jar to moquette-broker.jar

in jMQTTBrokerExtended.xml

changed from
<dependency>
<version>1</version>
<artifactId>moquette8</artifactId>
</dependency>

to
<dependency>
<version>1</version>
<artifactId>moquette-broker</artifactId>
</dependency>

Source b4j using broker.b4j without any changes.

Regards,
Sia
 

ilan

Expert
Licensed User
Longtime User
These jar files cannot work. Many classes are missing inside. The simplest solution is that Paris makes the file available on a Google Drive or Dropbox account because its size (3 MB) prevents it from being uploaded to the forum.

can you explain a little about the library (maybe in a new thread)? is it also for sale from your side? do you have example to see how it works? will it allow a full multiplayer option also when using libgdx and very fast games? (i have 0 experience with multiplayer but this topic always interested me and i really would like to build a real time multiplayer game)

thank you, ilan
 

Informatix

Expert
Licensed User
Longtime User
can you explain a little about the library (maybe in a new thread)? is it also for sale from your side? do you have example to see how it works? will it allow a full multiplayer option also when using libgdx and very fast games? (i have 0 experience with multiplayer but this topic always interested me and i really would like to build a real time multiplayer game)

thank you, ilan
This library was not made for fast & furious games. It is free since Paris posted it here.
 

paris7162

Member
Licensed User
Longtime User
This is a MQTT Multiplayer Library created by one of the best B4A library creators and member in the B4X Community. I use his libraries in all of my games. I didn’t write any of this code and I told him I would keep his identity private unless he wanted to reveal who he is.

I use it to play a Multiplayer card game with an Android and iOS device. I couldn’t find a better way for and Android player to play and iPhone player. I uploaded the Broker.jar to my Linux Virtual Private Server. I send a list from B4a and a NSMutableArray (NSArray) from Xcode in Objective C.

I used the following pods to install the library on my iOS devices.
pod 'MQTTClient/MinL'
pod 'MQTTClient/ManagerL'
pod 'MQTTClient/WebsocketL'


Here is the explanation on how to use the library.

Step by step to try the demos:
- download the archive and copy the content of Lib to the directory of additional libraries of B4J;
- set a valid port number in Broker/Broker. b4j (line 10);
- open this port on your server, if necessary;
- compile the Broker.b4j project;
- upload the result (Broker.jar) on your server and execute it;
- in the two projects under Demo_Clients, enter the IP address of the server and the port used by the broker (B4A: lines 28 and 29; B4J: lines 19 and 20);
- in the Client.b4a project, you can change the method of identification of the device line 48 (the goal is that the device is identified with an unique ID; the demo code will work but that won’t be the case in a real application with many users because some devices share the same android_id);
- in the Client.b4j project, you can also change the ClientID and put whatever you want;
- run the clients and click on the Connect button.

I've used this for 2 years and it works perfectly so far. Feel free to use this however you like. B4J has been updated a few times since then so I hope this still compiles. I'm the worst programmer so I can't be of much help to anyone but I will answer what I can.


Here is the link to the moquette8.jar file.

 

omo

Active Member
Licensed User
Longtime User
I changed...
This message is addressed to you and all other members that have tried this example. I just created time to test it out to see how it works first before thinking of where to adapt it. I changed the code to public cloud broker and port for quick testing. I used that of Android for testing by putting on two phones. Everything on the two phones connected successfully and ready, but I can't see any card game here for me to test further so I can adapt the logic for other things.

How do I use it to play simple card game or other simple game. If it were chatting apps now, since connection is established, then I will be sending messages. However, in this case I was just looking at connection established, ready to work, but can't see any card game to play and test it. Please, can anybody use simple game or non-game example in the forum to demonstrate how to use multiplayer further. Thank you all!
 
Top