Search code examples
swiftejabberdxmppframework

Stuck when connect to server when using xmppFramework


I started with xmppFramework with iOS and locally ejabberd server (running on "localhost:5280"). I logged in ejabberd server by using "username: admin, password: admin"

I checked my code correctly and add delegate "XMPPStreamDelegate". I face problem that my code call the delegate function "xmppStreamWillConnect" but it didn't call "xmppStreamDidConnect".

Genrally, what may cause this issue?

My code:

func connect() {
    if !self.xmppStream.isDisconnected() {
        return
    }
    self.xmppStream.hostName = "localhost:5280"
    self.xmppStream.myJID = XMPPJID(string:"admin@localhost")
    try! self.xmppStream.connect(withTimeout: 10)
    if self.xmppStream.isConnected(){
        print(true)
    }
    self.xmppStream.startTLSPolicy = XMPPStreamStartTLSPolicy.required
    self.xmppStream.supportsStartTLS()
    print("ok")
}

func xmppStreamWillConnect(_ sender: XMPPStream!) {
    print("will connect ")
}
func xmppStreamDidConnect(_ stream: XMPPStream!) {
    print("Stream: Connected")
    try! stream.authenticate(withPassword: self.password)
}

The result of printing is : ok willConnect


Solution

  • If you make localhost, surly it will not work. Simulator will run on the localhost and you cannot run both on the same localhost.