XMPP 连接将错误连接超时 [英] XMPP connect will error connection-timeout
问题描述
我使用 swift 4 和 ios 10.我正在使用 XMPPFramework,但无法连接到服务器.我有这个错误:
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
我搜索了这种情况,但在网络上没有找到任何内容.我没有找到 XMPP 框架的任何文档.如果你有文件,请发给我.我只是超时错误,我不知道是什么.这是我的代码:
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
推荐答案
最后,我解决了我的问题.我将 dd DDLog.add(DDTTYLogger.sharedInstance) 添加到我的代码中,我得到了更多信息.我使用网络功能连接,这有问题.func xmppStreamDidConnect(sender: XMPPStream!) { ... }它在文件中.所以我又写了这个函数.但它在 swift 4 中发生了变化.所以新代码是这样的:func xmppStreamDidConnect(_ 发件人: XMPPStream) { ... }所以,第二个函数(ew 函数)没有!"XMPPStream 后的符号.所以 Swift 认为第二个函数是一个新函数.不覆盖确实连接功能.所以当我连接到服务器时,服务器正在等待我,我的功能没有任何东西,我有一个空闲连接消息的错误
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
这篇关于XMPP 连接将错误连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!