XMPP connect will error connection-timeout

不羁的心 提交于 2020-02-25 06:20:18

问题


I use swift 4 and ios 10. I am using XMPPFramework and I can't connect to the server. I have this error :

stream:error xmlns:stream="http://etherx.jabber.org/streams"
connection-timeout xmlns="urn:ietf:params:xml:ns:xmpp-streams"
text xmlns="urn:ietf:params:xml:ns:xmpp-streams" lang="en" Idle connection

I search for this situation and I didn't find anything in the web. I didn't find any documentation for XMPP framework. if you have a document please send me it. I just have time out error and I don't know what is it. this is my code :

    class ViewController: UIViewController, XMPPStreamDelegate {
    var stream:XMPPStream!
    var xmppRoster: XMPPRoster!

    override func viewDidLoad() {
        super.viewDidLoad()
        let xmppRosterStorage = XMPPRosterCoreDataStorage()
        xmppRoster = XMPPRoster(rosterStorage: xmppRosterStorage)

        stream = XMPPStream()
        stream.addDelegate(self, delegateQueue: .main)
        xmppRoster.activate(stream)


        stream.hostPort = 5222
        stream.myJID = XMPPJID(string: "emad@chat.myaddress.net")

        do {
            print("start connect")
            try stream.connect(withTimeout: 30)
            print("request sent")
        }
        catch {
            print("catch")

        }
    }

    func xmppStreamWillConnect(sender: XMPPStream!) {
        print("will connect")
    }

    func xmppStreamConnectDidTimeout(_ sender: XMPPStream!) {
        print("timeout:")
    }

    func xmppStreamDidConnect(sender: XMPPStream!) {
        print("connected")

        do {
            try sender.authenticate(withPassword: "1235")
        }
        catch {
            print("catch")

        }

    }


    func xmppStreamDidAuthenticate(_ sender: XMPPStream!) {
        print("auth done")
        sender.send(XMPPPresence())
    }


    func xmppStream(_ sender: XMPPStream!, didNotAuthenticate error: DDXMLElement!) {
        print("dint not auth")
        print(error)
    }

    func xmppStream(sender: XMPPStream!, didReceivePresence presence: XMPPPresence!) {
        print(presence)
        let presenceType = presence.type()
        let username = sender.myJID.user
        let presenceFromUser = presence.from().user

        if presenceFromUser != username  {
            if presenceType == "available" {
                print("available")
            }
            else if presenceType == "subscribe" {
                self.xmppRoster.subscribePresence(toUser: presence.from())
            }
            else {
                print("presence type"); print(presenceType)
            }
        }

    }

    func xmppStream(_ sender: XMPPStream!, didReceiveError error: DDXMLElement!) {
        print("\(error)")
    }
    }

I have a problem with the first step. connecting to the server please help. I am really tired


回答1:


Finally, I fixed my issue. I add dd DDLog.add(DDTTYLogger.sharedInstance) to my codes and i get more information. I used web functions to connect and this has a problem. func xmppStreamDidConnect(sender: XMPPStream!) { ... } it was in the document. so I write this function again. but it was changed in swift 4. so new code was like this: func xmppStreamDidConnect(_ sender: XMPPStream) { ... } so, second function (ew function) has not "!" symbol after XMPPStream. So Swift thought of the second function as a new one. not override for did connect function. so when I was connected to the server, server was waiting for me and my function didn't anything and I had an error with an idle connection message



来源:https://stackoverflow.com/questions/59747578/xmpp-connect-will-error-connection-timeout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!