ios - XMPP连接将错误连接超时

标签 ios swift xmpp xmppframework

我使用swift 4和ios 10。
我正在使用XMPPFramework,但无法连接到服务器。我有这个错误:

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

我正在搜索这种情况,但在网上找不到任何内容。我没有找到有关XMPP框架的任何文档。如果您有文件,请寄给我。
我只是超时错误,不知道这是什么。
这是我的代码:
    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)")
    }
    }


我的第一步有问题。连接到服务器
请帮忙。我真的很累了

最佳答案

最后,我解决了我的问题。我将dd DDLog.add(DDTTYLogger.sharedInstance)添加到我的代码中,并获得更多信息。
我使用网络功能进行连接,这有问题。
func xmppStreamDidConnect(发送方:XMPPStream!){...}
它在文档中。所以我再次写这个函数。但很快就进行了更改。因此新代码如下:
func xmppStreamDidConnect(_ sender:XMPPStream){...}
因此,第二个功能(ew功能)没有“!” XMPPStream之后的符号。
因此Swift认为第二个功能是一个新功能。没有覆盖没有连接功能。
因此,当我连接到服务器时,服务器正在等待我,而我的功能却什么也没有,并且空闲连接消息出现错误

关于ios - XMPP连接将错误连接超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59747578/

相关文章:

iphone - UISearchView 不显示搜索值

iPhone 4 "device not registered"...需要帮助备份一些应用程序数据

Swift 检测何时从 UIApplication.shared.open 返回

ios - 在 while 循环中更新 UIView 背景颜色

ssl - XMPP 的 Pidgin -- SSL 握手失败

javascript - Mobile Safari 视差滚动不起作用

ios - 意外的 CFBundleExecutable key 。 Aviary SDK Resources.bundle 中的包

ios - 在 MVVM + Coordinator 中,如何处理 subview ?

javascript - Strop 匿名登录出现错误

proxy - XMPP 代理 TLS 加密