![](/img/trans.png)
[英]How to re-register a WAMP callee after a reconnect using Autobahn Python with Twisted ReconnectingClientFactory?
[英]Python & Autobahn with Twisted: reset maxRetries within ReconnectingClientFactory
我正在嘗試重新連接客戶端,如果由於某種原因連接使用Python和Autobahn與Twisted“斷開”。
這里有一個很好的例子,使用ReconnectingClientFactory設置但我的問題是圍繞maxRetries。
在腳本執行期間,總共允許設置5的方式。
class EchoClientFactory(ReconnectingClientFactory, WebSocketClientFactory):
protocol = EchoClientProtocol
# http://twistedmatrix.com/documents/current/api/twisted.internet.protocol.ReconnectingClientFactory.html
#
maxDelay = 10
maxRetries = 5
def startedConnecting(self, connector):
print('Started to connect.')
def clientConnectionLost(self, connector, reason):
print('Lost connection. Reason: {}'.format(reason))
ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
def clientConnectionFailed(self, connector, reason):
print('Connection failed. Reason: {}'.format(reason))
ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
例如,如果出現問題並且客戶端在重試2次后連接,那么只剩下3個,並且在連接成功后該數字不會“重置”。
如何實現這一點,意味着在成功連接后將maxRetries重置為5 - 如果可能的話?
謝謝!
科斯塔斯
安排協議在成功ReconnectingClientFactory.resetDelay
后調用ReconnectingClientFactory.resetDelay
。 這會重置所有內容,以便退避邏輯重新開始。
應用程序需要調用此方法而不是自動重置狀態,因為即使TCP連接成功,您仍可能遇到連接問題,需要重試后退。 例如,服務器可能會通過“太忙,稍后再試”消息來響應您的身份驗證嘗試。 如果您的協議中可能發生這類事情,您應該在發生resetDelay
之后調用resetDelay
調用。 ReconnectingClientFactory
無法知道這是什么時候。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.