Connection issue to XMPP Server (#17)
Junkeri tech nepal opened 6 months ago
import tigase.jaxmpp.core.client.BareJID
import tigase.jaxmpp.core.client.JID
import tigase.jaxmpp.core.client.SessionObject
import tigase.jaxmpp.core.client.xmpp.modules.chat.MessageModule
import tigase.jaxmpp.core.client.xmpp.modules.chat.MessageModule.MessageReceivedHandler
import tigase.jaxmpp.core.client.xmpp.stanzas.Stanza
import tigase.jaxmpp.j2se.Jaxmpp
import tigase.jaxmpp.j2se.Presence.initialize
import java.util.concurrent.TimeUnit
import java.util.logging.ConsoleHandler
import java.util.logging.Handler
import java.util.logging.Level
import java.util.logging.Logger


fun main(args: Array<String>) {
    startXMPPJavaServer()
}

fun startXMPPJavaServer() {
    val contact = Jaxmpp()

    initialize(contact)

    val logger = Logger.getLogger("tigase.jaxmpp")
    val handler = ConsoleHandler()
    handler.level = Level.ALL
    logger.addHandler(handler)
    logger.level = Level.ALL

    println("Init....")

    contact.modulesManager.register(MessageModule())

    contact.properties.setUserProperty(SessionObject.USER_BARE_JID, BareJID.bareJIDInstance("swornim@localhost"))
    contact.properties.setUserProperty(SessionObject.PASSWORD, "swornim")

    contact.login(true)


    contact.eventBus.addHandler(
        MessageReceivedHandler.MessageReceivedEvent::class.java,
        MessageReceivedHandler { sessionObject, chat, stanza -> println("received message: " + stanza.body) })


    contact.send(Stanza.createMessage().apply {
        to = JID.jidInstance("swornim@localhost")

        body = "This is body"
        subject = "This is subject"
    })


    if (contact.isConnected) {
        println("Connected....")
        TimeUnit.MINUTES.sleep(1);
        contact.disconnect()
    } else {
        println("Not Connected....")
    }
}

**The logs i am getting after running kotlin based jaxmpp client ** This are the logs am getting after connecting to tigase xmpp server

Jun 15, 2024 12:51:47 AM tigase.jaxmpp.core.client.AbstractSessionObject clear
FINE: Clearing properties in scopes [stream]
Jun 15, 2024 12:51:47 AM tigase.jaxmpp.j2se.Jaxmpp login
FINE: state=disconnected cr=false
Jun 15, 2024 12:51:47 AM tigase.jaxmpp.j2se.eventbus.ThreadSafeEventBus$2 run
FINEST: Calling handler class class tigase.jaxmpp.core.client.xmpp.stream.XmppStreamsManager$1 with event class tigase.jaxmpp.core.client.SessionObject$ClearedHandler$ClearedEvent
Jun 15, 2024 12:51:47 AM tigase.jaxmpp.j2se.Jaxmpp createConnector
INFO: Using SocketConnector
Jun 15, 2024 12:51:47 AM tigase.jaxmpp.j2se.eventbus.ThreadSafeEventBus$2 run
FINEST: Calling handler class class tigase.jaxmpp.core.client.xmpp.modules.presence.PresenceModule$2 with event class tigase.jaxmpp.core.client.SessionObject$ClearedHandler$ClearedEvent
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.SocketConnector printLog
FINE: [scid=1 thread=1] Connector state changed: null->connecting
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.eventbus.ThreadSafeEventBus$2 run
FINEST: Calling handler class class tigase.jaxmpp.core.client.JaxmppCore$10 with event class tigase.jaxmpp.core.client.Connector$StateChangedHandler$StateChangedEvent
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.SocketConnector printLog
INFO: [scid=1 thread=1] Resolving SRV record of domain 'localhost'
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.SocketConnector printLog
FINE: [scid=1 thread=1] Using built-in resolver
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.SocketConnector printLog
FINER: [scid=1 thread=1] Preparing connection to [localhost:5222]
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.SocketConnector printLog
INFO: [scid=1 thread=1] Opening connection to localhost/127.0.0.1:5222
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.SocketConnector printLog
FINEST: [scid=1 thread=1] Starting worker...
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.SocketConnector printLog
FINEST: [scid=1 thread=1] Restarting XMPP Stream
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.Worker run
FINEST: 1292557637 Starting Thread[Socket-Worker-Thread,5,main]
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.SocketConnector printLog
FINEST: [scid=1 thread=1] Send : <stream:stream from='swornim@localhost' to='localhost' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.SocketConnector printLog
FINE: [scid=1 thread=1] Connector state changed: connecting->connected
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.eventbus.ThreadSafeEventBus$2 run
FINEST: Calling handler class class tigase.jaxmpp.core.client.xmpp.modules.StreamFeaturesModule$2 with event class tigase.jaxmpp.core.client.Connector$StreamRestartedHandler$StreamRestaredEvent
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.SocketConnector printLog
CONFIG: [scid=1 thread=1] Whitespace ping period is setted to nullms
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.core.client.xmpp.modules.StreamFeaturesModule streamRestarted
FINE: Pipelining is disabled
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.eventbus.ThreadSafeEventBus$2 run
FINEST: Calling handler class class tigase.jaxmpp.core.client.JaxmppCore$10 with event class tigase.jaxmpp.core.client.Connector$StateChangedHandler$StateChangedEvent
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.Worker run
FINEST: 1292557637 / Disconnecting: state=connected; isInterrupted():false; buffer=-1 Thread[Socket-Worker-Thread,5,main]
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.SocketConnector printLog
FINE: [scid=1 thread=19] Connector state changed: connected->disconnected
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.eventbus.ThreadSafeEventBus$2 run
FINEST: Calling handler class class tigase.jaxmpp.core.client.JaxmppCore$10 with event class tigase.jaxmpp.core.client.Connector$StateChangedHandler$StateChangedEvent
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.SocketConnector printLog
FINE: [scid=1 thread=19] Stream terminated
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.eventbus.ThreadSafeEventBus$2 run
FINEST: Calling handler class class tigase.jaxmpp.j2se.Jaxmpp$2 with event class tigase.jaxmpp.core.client.Connector$StateChangedHandler$StateChangedEvent
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.SocketConnector printLog
FINEST: [scid=1 thread=19] Terminating all workers
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.eventbus.ThreadSafeEventBus$2 run
FINEST: Calling handler class class tigase.jaxmpp.core.client.JaxmppCore$5 with event class tigase.jaxmpp.core.client.Connector$StreamTerminatedHandler$StreamTerminatedEvent
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.Worker interrupt
FINE: Worker Interrupted
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.eventbus.ThreadSafeEventBus$2 run
FINEST: Calling handler class class tigase.jaxmpp.core.client.xmpp.modules.StreamFeaturesModule$3 with event class tigase.jaxmpp.core.client.Connector$StreamTerminatedHandler$StreamTerminatedEvent
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.Worker interrupt
FINE: Worker Interrupted
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.eventbus.ThreadSafeEventBus$2 run
FINEST: Calling handler class class tigase.jaxmpp.j2se.Jaxmpp$2 with event class tigase.jaxmpp.core.client.Connector$StreamTerminatedHandler$StreamTerminatedEvent
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.Worker run
FINEST: Worker2 is interrupted
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.eventbus.ThreadSafeEventBus$2 run
FINEST: Calling handler class class tigase.jaxmpp.j2se.Jaxmpp$2 with event class tigase.jaxmpp.core.client.JaxmppCore$LoggedOutHandler$LoggedOutEvent
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.SocketConnector printLog
FINEST: [scid=1 thread=19] Worker terminated
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.eventbus.ThreadSafeEventBus$2 run
FINEST: Calling handler class class tigase.jaxmpp.core.client.JaxmppCore$5 with event class tigase.jaxmpp.core.client.Connector$StreamTerminatedHandler$StreamTerminatedEvent
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.eventbus.ThreadSafeEventBus$2 run
FINEST: Calling handler class class tigase.jaxmpp.core.client.xmpp.modules.StreamFeaturesModule$3 with event class tigase.jaxmpp.core.client.Connector$StreamTerminatedHandler$StreamTerminatedEvent
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.eventbus.ThreadSafeEventBus$2 run
FINEST: Calling handler class class tigase.jaxmpp.j2se.Jaxmpp$2 with event class tigase.jaxmpp.core.client.Connector$StreamTerminatedHandler$StreamTerminatedEvent
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.eventbus.ThreadSafeEventBus$2 run
FINEST: Calling handler class class tigase.jaxmpp.core.client.JaxmppCore$9 with event class tigase.jaxmpp.core.client.Connector$DisconnectedHandler$DisconnectedEvent
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.eventbus.ThreadSafeEventBus$2 run
FINEST: Calling handler class class tigase.jaxmpp.core.client.xmpp.modules.StreamFeaturesModule$4 with event class tigase.jaxmpp.core.client.Connector$DisconnectedHandler$DisconnectedEvent
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.eventbus.ThreadSafeEventBus$2 run
FINEST: Calling handler class class tigase.jaxmpp.j2se.Jaxmpp$2 with event class tigase.jaxmpp.core.client.Connector$DisconnectedHandler$DisconnectedEvent
Exception in thread "main" tigase.jaxmpp.core.client.exceptions.JaxmppException: Not connected!
at tigase.jaxmpp.core.client.JaxmppCore$DefaultPacketWriter.write(JaxmppCore.java:561)
at tigase.jaxmpp.core.client.JaxmppCore.send(JaxmppCore.java:271)
at MainKt.startXMPPJavaServer(Main.kt:42)
at MainKt.main(Main.kt:13)
wojciech.kapcia@tigase.net commented 6 months ago

Do you have localhost domain/vhost configured on your server?

Could you share logs from the server?

It looks like you just got disconnected without any reason nor any response:

FINEST: Calling handler class class tigase.jaxmpp.core.client.JaxmppCore$10 with event class tigase.jaxmpp.core.client.Connector$StateChangedHandler$StateChangedEvent
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.Worker run
FINEST: 1292557637 / Disconnecting: state=connected; isInterrupted():false; buffer=-1 Thread[Socket-Worker-Thread,5,main]
Jun 15, 2024 12:51:48 AM tigase.jaxmpp.j2se.connectors.socket.SocketConnector printLog
FINE: [scid=1 thread=19] Connector state changed: connected->disconnected

Can you try with adding following:

contact.getConnectionConfiguration().setConnectionType(ConnectionConfiguration.ConnectionType.socket);
contact.getConnectionConfiguration().setServer(server);

contact.getConnectionConfiguration().setUserJID(user.getBareJid());
contact.getConnectionConfiguration().setUserPassword(password);

issue 1 of 1
Type
New Feature
Priority
Normal
Assignee
Version
none
Sprints
n/a
Customer
n/a
Issue Votes (0)
Watchers (3)
Reference
tigase/_libraries/jaxmpp#17
Please wait...
Page is in error, reload to recover