powered by Jive Software

Smack api send message is not working

Hi Team

i am trying to make a connection and sending a message with openfire using smack java api.

i am not getting any error on my java code but not sure about message is delivered to openfire or not. To check this i used a convers.js client, connected it to openfire using configuration. It means whatever message i am sending from java code, should appear at converse chat window.
but message is not received to converse chat window.please find below java and converse.js configuration.
java code :-

Blockquote
DomainBareJid serviceName = JidCreate.domainBareFrom(“anonymous@conference.l-1054.con.com”);
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword(“admin”, “—”)
.setXmppDomain(serviceName)
.setHost(“localhost”)
.setPort(5222)
.setSecurityMode(SecurityMode.disabled) // Do not disable TLS except for test purposes!
.build();
AbstractXMPPConnection connection = new XMPPTCPConnection(config);
connection.connect().login();

	ChatManager chatManager = ChatManager.getInstanceFor(connection);
	chatManager.addIncomingListener(new IncomingChatMessageListener() {
	  @Override
	public
	  void newIncomingMessage(EntityBareJid from, Message message, Chat chat) {
	    System.out.println("New message from " + from + ": " + message.getBody());
	  }
	});
	EntityBareJid jid = JidCreate.entityBareFrom("anonymous@conference.l-1054.con.com");
	Chat chat = chatManager.chatWith(jid);
	chat.send("Howdy!");

Converse.js config :-

Blockquote
converse.initialize({
allow_logout: false,
allow_muc_invitations: false,
allow_contact_requests: false,
authentication: ‘anonymous’,
auto_login: true,
auto_join_rooms: [
‘anonymous@conference.l-1054.con.com’,
],
notify_all_room_messages: [
‘anonymous@conference.l-1054.con.com’,
],
bosh_service_url: ‘http://l-1054.con.com:7070/http-bind/’,
jid: ‘con.com’,
keepalive: true,
hide_muc_server: true,
play_sounds: true,
show_controlbox_by_default: true,
strict_plugin_dependencies: false,
});

Please check if i am doing anything wrong. where can i check the message in openfire (any logs or database).
in above code i am also confused whether i am inputting right jid (domainBareFrom / entityBareFrom).

Thanks in Advance.

I assume that your chat server is running on l-1054.con.com.
In that case you configured your connection wrong already.
Let’s say you want to login with user admin@l-1054.con.com. Then you’d have to do the following:

XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword(“admin@l-1054.con.com”, “—”)
.setSecurityMode(SecurityMode.disabled) // Do not disable TLS except for test purposes!
.build();

Make sure that your server is reachable via DNS, then you can refrain from doing manual error prone host/service/port configuration.

If you however need to do such manual configuration, your serviceDomain is probably l-1054.con.com. What you were using is the service domain of the conference service, which is not of interest for you.
It also appears that you are trying to send a message in a MUC, for which you have to use the MultiUserChatManager. The ChatManager is used for 1:1 chats only.

If you want to contact a user via 1:1 chat, then you also need to use an EntityBareJid of the format user@l-1054.con.com. On the other hand anonymous@conference.l-1054.con.com is the address of a multi user chat (conference). So if you instead want to contact the user via MUC, use that address.

Thanks Paul,

I am now able to get and send messages.

The problem was i am not using “MultiUserChatManager”.

1 Like

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.