B4A Library XMPP/JABBER - Best protocol to IM for B4A

XmppTop.png

XMPP/JABBER - Best protocol to Instant Messengers for B4A

This library was made based on XMPP Protocol

Installation instructions:
- Copy the .xml and .jar(s) files to your custom libraries folder
- Select in your REFERENCED LIBRARIES

ReferenceXMPP.jpg



Version history:
V1.0.0 (First public release - Donationware):
- Initial version

V1.0.1:
- Fix bug username

V1.0.2:
- Create 4 for events (ErrorSendMessage,ErrorConnect,ErrorLogin,PresenceChanged)
-
Create Methods: ChangeStatus, ActivatePresence
- Implemented correction in case the Name is Null

*Obs: PresenceChanged depends of each server.
Was observed in tests that some servers do not support the "presence listener"


V1.0.3:
- Fix bug when use XMPP and MQTT together

V1.0.4:
- Fix bug when use XMPP in some cases with threads

XMPP
Author:
Alberto Iglesias - alberto@visualnet.inf.br
Version: 1.0.4
  • XMPP
    Events:
    • deliverycomplete (Message As String)
    • messageArrived (Message As String)
    • onConnect ()
    • onDisconnect ()
    • onDisconnect (Status as boolean As )
    • onInitialized ()
    • onLogin ()
    • ErrorSendMessage(Error As String)
    • ErrorConnect(Error As String)
    • ErrorLogin(Error As String)
    • PresenceChanged(Presence As String)
    Fields:
    • Host As String
      Name or IP of the Jabber/XMPP Server
    • JavaDebug As Boolean
      Enable/Disable Debug from Java Code
    • Port As Int
      Port of the Jabber/XMPP Server
    Methods:
    • About As String
      About the developer
    • Connect
      Connect to the Jabber/XMPP Server
    • ChangeStatus(int iStatus)
      Change the status of your client
    • CreateChat (userJID As String)
      Create Chat with the JIB User
    • Disconnect
      Disconnect from Jabber/XMPP Server
    • GetHost As String
      Returns the host name of the server where the XMPP server is running
    • GetRoster As List
      Get Roster List
    • GetUser As String
      Get the connection current user
    • Initialize (eventname As String)
      Initializing XMPP Object
    • IsConnected As Boolean
      Get a connection status
    • IsSecureConnection As Boolean
      Check if the connection is secure
    • Login (Username As String, Password As String)
      Login into to the Jabber/XMPP Server
    • SendMessage (message As String)
      Send a message into the chat
    • Version As String
      Get the Library Version
    Permissions:
    • android.permission.ACCESS_WIFI_STATE
    • android.permission.INTERNET

ScreenXMPP.jpg


Xmpp1.jpg


Xmpp2.png


You can try your APP using web client in https://jwchat.org/


References:
http://xmpp.org/
https://jwchat.org/

* This version is fully functional, the only one difference is when sending a message the text "Donationware" is delivery with your message.
Please consider a simple €10 donation and I send to you the Library without "Donationware" text in a sendmessage method.





Version 1.0.4

Look others libraries in http://www.visualnet.inf.br/store


* Put in this link because this forum accept only 512k maximum.
 

Attachments

  • Example1.zip
    12.8 KB · Views: 599
  • Example3.zip
    13 KB · Views: 538
Last edited:

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
It´s easy:

1) Create your account in any Jabber server: In my test case I create in thir URL https://jabber.chaotic.de:5282/register/new
2) Connect with server
3) Login with your account created
4) Imagine you chat with somebody, the use the CreateChat method passing another person UserID ( In my case I created 2 accounts to tests)
5) Now is like you have a IM program with chat window open, then you can send and receive messages


Have a lot of servers use this protocol, like Google Talk, etc.
 

coslad

Well-Known Member
Licensed User
Longtime User
Alberto can explain us why to use xmpp in place of mqtt ?
 

itgirl

Active Member
Licensed User
Longtime User
Long waited one , i have to play around with this one , thank you ;)
 

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Hello Coslad, Mqtt and xmpp are different concepts. One is not change for another.

MQTT is for generic use, can be used for IM too, but XMPP is more specific and matured for IM.

For example, I use MQTT for a project to future cars connected and with this project I never used XMPP.

For create Chat Groups, IM programs, I recommend XMPP.


image0011.jpg
 

coslad

Well-Known Member
Licensed User
Longtime User
Thanks Alberto , now it is a little bit more clear .
I tried your sample code but .....:

When i send the "createchat" command :
objXmpp.CreateChat(pippo@jabber.chaotic.de)
The server doesn't give me back nothing , so i don't know if the other user is on line or not .
At this point if i send a message , and , the other users are not online the message is lost.
The Event objXmpp_DeliveryComplete if fired but the message is lost.
am i wrong ?
 

coslad

Well-Known Member
Licensed User
Longtime User
ok i'll try.

now , if for example i would like to implement this function i a my app, is there a server which accept registration request direct from my application .
i explain better : like every im apps the user register his account from app inside and not from a web page.
Another question , it seems that xmpp doesn't supports multi user chat, right ?
 

coslad

Well-Known Member
Licensed User
Longtime User
Hi Alberto i'm tryng your library but i found some troubles :

1) The getroster comand return the error :

java.lang.NullPointerException at java.lang.String.concat(String.java:678)

even if the client is connected and a chat is active .

2) I have User1 and User2 , User1 is the android app and User2 is the Xpmm web client.
User1(app) is connected and logged in the server
User2(web) is connected and logged too,

User2(web) sees that User1(app) is online
User2(web) send a message , the message is not delivered ,only when User1(app) set a "CreateChat" and send message to User2 (web) the message is delivered ,only after this the User2(web) can send message to User1(app)

3)User1(app) is connected , User2(web) is not connected

User1(app) createChat and send a message , it returns the event "Delivered"but delivered to who ? (User2 is not connected)
 

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Hi Coslad,

For the 1st question I will try in here, maybe don´t having any users in chat, you get this null, I don´t know, I will check this.

For the 2nd, I think is problem the server because in my tests with server "jabber.chaotic.de" I don´t see this behavior.

Try with my tests accounts in both sides, please:

Server: jabber.chaotic.de

User1: visualnet@jabber.chaotic.de
Pwd: MyJabber2015

User2: visualfriend@jabber.chaotic.de
Pwd: MyJabber2015
 

coslad

Well-Known Member
Licensed User
Longtime User
Ok i have made a try.

1)User1 (App) , User2 (WEB)

User1 > connect > Login --Nothing else
User2(web) >Login > in the list is listed visulalfriend so i sended a message from the web to phone , but nothing happen

After:

User1(app) "createchat" and sent a message to visualnet (message is delivered)
User2(Web) > send message to visualfriend and the message is delivered

Now i have closed the web browser and have tryed to send a message from User1(app ) to User2(web offline) , the application says : objxmpp_deliverycomplete , but the user2 is offline

PS: The "Getroaster" with this two user works fine!
Maybe is there a sort of autorization before i can add a user to my list ?
 

coslad

Well-Known Member
Licensed User
Longtime User
Alberto with this two user the GetRoaster crash

App:

pippo
pippo

Web :

pluto
pluto

can you try ?
 

coslad

Well-Known Member
Licensed User
Longtime User
The server is jabber.chaotic.de

as written in the post above :

User 1: pippo
Pass1: pippo

User2: pluto
Pass2: pluto


as web client i use https://jwchat.org/
If you set the user1(pippo) as user into your sample app and the user2 not in the app but in the web , clicking to getroaser the app crash.

obviously i set the user2 (pluto@jabber.chaotic.de) in the command "createchat"
 

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Hey Coslad,

In the asmack library I found when get the name, and is null, catch a exception..

Now I put a catch in a new version of library, try now with version 1.0.1 (I put in the first post)



public Collection<RosterEntry> getRosterEntries() {
Collection<RosterEntry> entries = roster.getEntries();
for (RosterEntry entry : entries) {
Log.d("SmackXMPP", "RosterEntry " + entry);
Log.d("SmackXMPP","User: " + entry.getUser());
Log.d("SmackXMPP","Name: " + entry.getName());
Log.d("SmackXMPP","Status: " + entry.getStatus());
Log.d("SmackXMPP","Type: " + entry.getType());
Presence entryPresence = roster.getPresence(entry.getUser());
Log.d("SmackXMPP", "Presence Status: " + entryPresence.getStatus());
Log.d("SmackXMPP", "Presence Type: "+ entryPresence.getType());
Presence.Type type = entryPresence.getType();
if (type == Presence.Type.available)
Log.d("SmackXMPP", "Presence AVIALABLE");
Log.d("SmackXMPP", "Presence : "+ entryPresence);
}

return entries;

}
 

coslad

Well-Known Member
Licensed User
Longtime User
Ok Alberto now it works !, but ....................

Why Name is = Null ?

If i use your username and password the name is .visualfriend@jabber.chaotic.de , but if i use pluto@jabber.chaotic.de as user , the name is null !
And, remain the problem that if pluto(web app) sees pippo (app) online and send a message , the message is not delivered untill pippo(app) send the createchat.
Furthermore, the web app immediately realizes if a user changes state from offline to online, while in the library there 'an event

anyway, good job!
 
Top