How to implement muc with smack

317 views
Skip to first unread message

Jonathan Zanella

unread,
Feb 12, 2015, 4:00:58 PM2/12/15
to prosod...@googlegroups.com
Hi

I have an already running prosody server and now I need to implement MUC.

I already added the <Component "conference.my-server.com.br" "muc"> line to the prosody.clg.lua and restarted the server.

The client of the server is an Android app that uses smack to connect to the server. When the user joins the MUC, the following code is executed:

Presence joinPresence = new Presence(Presence.Type.available);
joinPresence.setTo(mThreadId);
joinPresence.addExtension(new MUCInitialPresence());

XMPPConnection conx = Application.getInstance().getXMPPConection();
PacketFilter responseFilter = new AndFilter(new FromMatchesFilter(mThreadId), new PacketTypeFilter(Presence.class));

PacketCollector response = conx.createPacketCollector(responseFilter);
conx.sendPacket(joinPresence);

Presence presence = (Presence) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
response.cancel();

if (presence == null) {
    Log.e("XMPP", "No response from server.");
} else if (presence.getError() != null) {
    Log.e("XMPP", presence.getError().toString());
}

The mThreadId is a variable that contains the id of an item in the database(each item has one chat). 

When I try to send the presence, the server returns "service-unavailable(-1)".

The prosody log shows:

  Out of connection options, can't connect to <mThreadId>

   Sending error replies for 1 queued stanzas because of failed outgoing connection to <mThreadId>

I searched for this message in the forum and I found that when you try to log with an user without the @my-server.com it happens. So I added the @my-server.com at the thread. The errors stopped to happen, but the chat didn't work.

To send a message, I use the following code:


org.jivesoftware.smack.packet.Message message = new org.jivesoftware.smack.packet.Message();
message.setType(org.jivesoftware.smack.packet.Message.Type.groupchat);

message.setBody(body);
message.setThread(mThreadId + "@my-server.com");

boolean messageSent = true;

XMPPConnection conx = Application.getInstance().getXMPPConection();
if (conx != null)
conx.sendPacket(message);
else
messageSent = false;
} catch (IllegalStateException e) {
if (e.getMessage().compareTo("Not connected to server.") == 0) {
messageSent = false;
}
}


Sorry for the long post, but I tried to add as much information as I can.

Someone knows why my muc doesn't work?


Matthew Wild

unread,
Feb 12, 2015, 8:54:09 PM2/12/15
to Prosody IM Users Group
Hi Jonathan,

On 12 February 2015 at 21:00, Jonathan Zanella
You're very close. Your error is also related to an incorrect address,
but your fix was wrong. The correct address of rooms should end with
@conference.my-server.com (not @my-server.com). It needs to match the
hostname you put in the Component directive in the config file for
your MUC service.

Hope this helps!

Regards,
Matthew

ashish gupta

unread,
May 28, 2015, 5:16:44 AM5/28/15
to prosod...@googlegroups.com
how's the format of  the mThreadId ?

i m using the mThreadId like x...@10.0.0.9.
is this fine ?

me prosody server is running on 10.0.0.9
there is created a user x...@10.0.0.9 with  password.
Reply all
Reply to author
Forward
0 new messages