如何断开我的 XMPPPY 客户端对象 [英] How do I disconnect my XMPPPY client object

查看:26
本文介绍了如何断开我的 XMPPPY 客户端对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 XMPPPY 连接到 XMPP 服务器很简单.

Connecting to an XMPP server with XMPPPY is simple.

from xmpp.client import Client as XMPPClient

self.xmppClient = XMPPClient("jabber.foo.com")
if not self.xmppClient.connect(server="localhost"):
    raise IOError('Cannot connect to server.')
if not self.xmppClient.auth("node", "password", "resource"):
    raise IOError('Can not auth with server.')
    self.xmppClient.RegisterHandler("message", self.messageHandler)
self.xmppClient.sendInitPresence()

但是,有时我的客户不得不强制断开连接,但仍继续做其他事情.我想确保客户端正确断开连接 - 套接字没有闲逛"并且服务器资源没有被浪费.

However, there are times when my client has to force a disconnect, yet still keep going doing other things. I'd like to make sure that the client disconnects properly - that the socket is not 'hanging around' and the server resources are not being wasted.

预期的模式是简单地将客户端设置为 None 并让 GC 清理对象吗?

Is the intended pattern to simply set the client to None and let GC clean up the object?

self.xmppClient = None

我在客户端看到断开连接的处理程序",但我不知道如何调用它们.而且 XMPPPY 附带的文档很糟糕.

I see "disconnected handlers" in the client, but I do not see how to invoke them. And the documentation that comes with XMPPPY is horrible.

有人知道断开连接的正确方法"吗?

Anyone have any clue of the "right way" to disconnect?

推荐答案

xmpp.dispatcher.Dispatcher 类有一个 disconnect() 方法.从自动生成的文档中看并不明显,因为它是通过 PlugIn 机制动态加载的,但您可以在任何 CommentClient 对象上使用它.

The xmpp.dispatcher.Dispatcher class has a disconnect() method. It's not obvious from the automatically generated documentation as it's loaded dynamically through the PlugIn mechanism, but you can use it on any CommentClient object.

这篇关于如何断开我的 XMPPPY 客户端对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆