powered by Jive Software

Smack websocket connection using 4.5.0 alpha1

Hi Team

i am trying to connect openfire server with websocket using 4.5.0 alpha1 lib from past 1 week but unable to connect.

Dont know how can i make connection, send and receive messages in case of websocket.

could you please provide me any example or give me direction.

my code

Blockquote
DomainBareJid serviceName = JidCreate.domainBareFrom(“1054.com”);
EntityBareJid user = JidCreate.entityBareFrom(“manu@1054.com”);
ModularXmppClientToServerConnectionConfiguration.Builder builder = ModularXmppClientToServerConnectionConfiguration.builder();
builder.removeAllModules().setXmppDomain(serviceName)
.setSendPresence(true)
.setHost(“localhost”)
.setSecurityMode(SecurityMode.disabled)
;
builder.setXmppAddressAndPassword(user, “password”);
//handshakeHttps();
// Set a fallback uri into websocket transport descriptor and add this descriptor into connection builder.
XmppWebSocketTransportModuleDescriptor.Builder websocketBuilder = XmppWebSocketTransportModuleDescriptor.getBuilder(builder);
websocketBuilder.explicitlySetWebSocketEndpointAndDiscovery(new URI(“ws://1054.com:7070/ws/”), false);

    builder.addModule(websocketBuilder.build());

    ModularXmppClientToServerConnectionConfiguration config = builder.build();
    ModularXmppClientToServerConnection connection = new ModularXmppClientToServerConnection(config);
    connection.setParsingExceptionCallback(new ExceptionThrowingCallbackWithHint());
    
    connection.connect();
    
    final String messageBody = ": Hello from the other side!";
    Message message = connection.getStanzaFactory().buildMessageStanza()
                    .to("sandeep@1054.com")
                    .setBody(messageBody)
                    .build();
    
    connection.login();
    connection.sendStanza(message);
    connection.disconnect();

Please help.
This code i got from below link

i am getting below error

Blockquote
Oct 14, 2020 7:08:06 PM org.jivesoftware.smack.AbstractXMPPConnection parseAndProcessNonza
SEVERE: Unknown nonza: {urn:ietf:params:xml:ns:xmpp-framing}open
Oct 14, 2020 7:08:06 PM org.jivesoftware.smackx.xdata.provider.DataFormProvider parseField
WARNING: The Field ‘os’ from FORM_TYPE ‘urn:xmpp:dataforms:softwareinfo’ is not registered. Field type is unknown, assuming text-single.
Oct 14, 2020 7:08:06 PM org.jivesoftware.smackx.xdata.provider.DataFormProvider parseField
WARNING: The Field ‘os_version’ from FORM_TYPE ‘urn:xmpp:dataforms:softwareinfo’ is not registered. Field type is unknown, assuming text-single.
Oct 14, 2020 7:08:06 PM org.jivesoftware.smackx.xdata.provider.DataFormProvider parseField
WARNING: The Field ‘software’ from FORM_TYPE ‘urn:xmpp:dataforms:softwareinfo’ is not registered. Field type is unknown, assuming text-single.
Oct 14, 2020 7:08:06 PM org.jivesoftware.smackx.xdata.provider.DataFormProvider parseField
WARNING: The Field ‘software_version’ from FORM_TYPE ‘urn:xmpp:dataforms:softwareinfo’ is not registered. Field type is unknown, assuming text-single.
Oct 14, 2020 7:08:06 PM org.jivesoftware.smackx.xdata.provider.DataFormProvider parseField
WARNING: The Field ‘admin-addresses’ from FORM_TYPE ‘http://jabber.org/network/serverinfo’ is not registered. Field type is unknown, assuming text-single.
Oct 14, 2020 7:08:06 PM com.openfire.controller.ExceptionThrowingCallbackWithHint handleUnparsableStanza
WARNING: Parsing exception encountered. This exception will be re-thrown, leading to a disconnect. You can change this behavior by setting a different ParsingExceptionCallback using setParsingExceptionCallback(). More information an be found in AbstractXMPPConnection’s javadoc.
Oct 14, 2020 7:08:11 PM org.jivesoftware.smackx.xdata.provider.DataFormProvider parseField
WARNING: The Field ‘os’ from FORM_TYPE ‘urn:xmpp:dataforms:softwareinfo’ is not registered. Field type is unknown, assuming text-single.
Oct 14, 2020 7:08:11 PM org.jivesoftware.smackx.xdata.provider.DataFormProvider parseField
WARNING: The Field ‘os_version’ from FORM_TYPE ‘urn:xmpp:dataforms:softwareinfo’ is not registered. Field type is unknown, assuming text-single.
Oct 14, 2020 7:08:11 PM org.jivesoftware.smackx.xdata.provider.DataFormProvider parseField
WARNING: The Field ‘software’ from FORM_TYPE ‘urn:xmpp:dataforms:softwareinfo’ is not registered. Field type is unknown, assuming text-single.
Oct 14, 2020 7:08:11 PM org.jivesoftware.smackx.xdata.provider.DataFormProvider parseField
WARNING: The Field ‘software_version’ from FORM_TYPE ‘urn:xmpp:dataforms:softwareinfo’ is not registered. Field type is unknown, assuming text-single.
Oct 14, 2020 7:08:11 PM org.jivesoftware.smackx.xdata.provider.DataFormProvider parseField
WARNING: The Field ‘admin-addresses’ from FORM_TYPE ‘http://jabber.org/network/serverinfo’ is not registered. Field type is unknown, assuming text-single.
Oct 14, 2020 7:08:11 PM com.openfire.controller.ExceptionThrowingCallbackWithHint handleUnparsableStanza
WARNING: Parsing exception encountered. This exception will be re-thrown, leading to a disconnect. You can change this behavior by setting a different ParsingExceptionCallback using setParsingExceptionCallback(). More information an be found in AbstractXMPPConnection’s javadoc.
Oct 14, 2020 7:08:16 PM org.jivesoftware.smackx.httpfileupload.HttpFileUploadManager$2 authenticated
WARNING: Error during discovering HTTP File Upload service
org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). StanzaCollector has been cancelled. Waited for response using: IQReplyFilter: iqAndIdFilter (AndFilter: (OrFilter: (IQTypeFilter: type=error, IQTypeFilter: type=result), StanzaIdFilter: id=MNUZB-3)), : fromFilter (OrFilter: (FromMatchesFilter (full): 1054.com)).
** at** org.jivesoftware.smack.SmackException$NoResponseException.newWith(SmackException.java:124)
at org.jivesoftware.smack.SmackException$NoResponseException.newWith(SmackException.java:104)
at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:281)
at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:228)
at org.jivesoftware.smackx.disco.ServiceDiscoveryManager.discoverInfo(ServiceDiscoveryManager.java:606)
at org.jivesoftware.smackx.disco.ServiceDiscoveryManager.discoverInfo(ServiceDiscoveryManager.java:578)
at org.jivesoftware.smackx.disco.ServiceDiscoveryManager.findServicesDiscoverInfo(ServiceDiscoveryManager.java:813)
at org.jivesoftware.smackx.disco.ServiceDiscoveryManager.findServicesDiscoverInfo(ServiceDiscoveryManager.java:781)
at org.jivesoftware.smackx.disco.ServiceDiscoveryManager.findServicesDiscoverInfo(ServiceDiscoveryManager.java:761)
at org.jivesoftware.smackx.httpfileupload.HttpFileUploadManager.discoverUploadService(HttpFileUploadManager.java:192)
at org.jivesoftware.smackx.httpfileupload.HttpFileUploadManager$2.authenticated(HttpFileUploadManager.java:129)
at org.jivesoftware.smack.AbstractXMPPConnection.callConnectionAuthenticatedListener(AbstractXMPPConnection.java:1706)
at org.jivesoftware.smack.AbstractXMPPConnection.afterSuccessfulLogin(AbstractXMPPConnection.java:797)
at org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection.access$2800(ModularXmppClientToServerConnection.java:89)
at org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection$AuthenticatedAndResourceBoundState.transitionInto(ModularXmppClientToServerConnection.java:909)
at org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection.attemptEnterState(ModularXmppClientToServerConnection.java:420)
at org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection.walkStateGraphInternal(ModularXmppClientToServerConnection.java:350)
at org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection.walkStateGraph(ModularXmppClientToServerConnection.java:292)
at org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection.walkStateGraphInternal(ModularXmppClientToServerConnection.java:372)
at org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection.walkStateGraph(ModularXmppClientToServerConnection.java:292)
at org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection.walkStateGraphInternal(ModularXmppClientToServerConnection.java:372)
at org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection.walkStateGraph(ModularXmppClientToServerConnection.java:292)
at org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection.walkStateGraphInternal(ModularXmppClientToServerConnection.java:372)
at org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection.walkStateGraph(ModularXmppClientToServerConnection.java:292)
at org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection.loginInternal(ModularXmppClientToServerConnection.java:269)
at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:643)
at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:600)
at com.openfire.controller.OpenfireXMPPWebSocketClient.main(OpenfireXMPPWebSocketClient.java:61)
Oct 14, 2020 7:08:16 PM org.jivesoftware.smack.websocket.okhttp.OkHttpWebSocket disconnect
INFO: WebSocket has been closed with message: WebSocket closed normally

i am able to resolve above errors.

Errors are comming because smack liberary and dependency are not correctly configured in build path.

because for 4.5.0 alpha1 there no mavan or gradle repository available , i configured all smack libs and dependencies manually and then it started giving error.

Now i configured below jars in build path
smack-extensions-4.5.0-alpha1-SNAPSHOT.jar
smack-im-4.5.0-alpha1-SNAPSHOT.jar
smack-tcp-4.5.0-alpha1-SNAPSHOT.jar
smack-sasl-javax-4.5.0-alpha1-SNAPSHOT.jar
smack-resolver-javax-4.5.0-alpha1-SNAPSHOT.jar
xpp3-1.1.4c.jar
smack-core-4.5.0-alpha1-SNAPSHOT.jar
smack-java8-4.5.0-alpha1-SNAPSHOT.jar
smack-xmlparser-4.5.0-alpha1-SNAPSHOT.jar
smack-xmlparser-stax-4.5.0-alpha1-SNAPSHOT.jar
smack-xmlparser-xpp3-4.5.0-alpha1-SNAPSHOT.jar
smack-streammanagement-4.5.0-alpha1-SNAPSHOT.jar
minidns-core-1.0.0.jar
smack-websocket-4.5.0-alpha1-SNAPSHOT.jar
smack-websocket-okhttp-4.5.0-alpha1-SNAPSHOT.jar
okhttp-4.2.2.jar
kotlin-stdlib-1.3.21.jar
okio-2.2.2.jar
jxmpp-core-1.0.1.jar
jxmpp-jid-1.0.1.jar
jxmpp-util-cache-1.0.1.jar

Now i just wanted to know, how we can use WebsocketFactoryService to get websocket objects and use them to send and receive message and events?

You don’t have to manually interact with the Websocket at all.
Smack will use the websocket connection to send and receive stanzas transparently.

Simply continue using Smack as you would usually do when using it with a tcp connection.