如何强制断开使用autobahn.websocket python软件包创建的Web套接字客户端的连接?

时间:2018-07-20 18:04:54

标签: python-2.7 websocket automation autobahn

我的实际代码文件如下:

from autobahn.twisted.websocket import WebSocketClientProtocol, 
WebSocketClientFactory, connectWS
from twisted.internet import reactor, ssl

class webSocketOperations(WebSocketClientProtocol):
    def kill_connection(self,exit_code=1000,reason=None):
        self.sendClose(1000,reason)

def stop_websocket():
    class_obj = SomeClass()
    class_obj.kill_connection(1000,"normal exit from websocket")

def start_websocket():
    url = "wss://someurl"
    factory = WebSocketClientFactory(url)
    factory.protocol = webSocketOperations
    connectWS(factory)
    reactor.run()

从中进行呼叫的另一个文件看起来像 假设所有进口都是

start_websocket()
stop_websocket()

当我运行更高版本的文件时,出现的错误是:

AttributeError: 'webSocketOperations' object has no attribute 'state'

0 个答案:

没有答案