从AMP;p调用方法

2024-09-28 01:29:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试实现对自己定义的属于AMP协议的方法的调用。你知道吗

我跟着下一步走。 在客户端,我启动了一个反应器,如下所示。你知道吗

connector = reactor.connectSSL('localhost', 1234,\
 ClientReconnectFactory(self.CONNECTION_INFO, gsi),\
  ClientContextFactory())

self.CONNECTION_INFO为连接过程保存一些有用的变量。你知道吗

gsi是一个用一些方法调用类的变量。你知道吗

gsi = GroundStationInterface(self.CONNECTION_INFO, "Vigo", ClientProtocol)

ClientReconnectFactory是从ReconnectingClientFactory继承的对象,代码如下:

def __init__(self, CONNECTION_INFO, gsi):
    self.CONNECTION_INFO = CONNECTION_INFO
    self.gsi = gsi
    # self.continueTrying = 0

def startedConnecting(self, connector):
    log.msg('Starting connection...')

def buildProtocol(self, addr):
    log.msg('Building protocol...')
    self.resetDelay()
    return ClientProtocol(self.CONNECTION_INFO, self.gsi)

def clientConnectionLost(self, connector, reason):
    self.continueTrying = None

    log.msg('Lost connection. Reason: ', reason)
    ReconnectingClientFactory.clientConnectionLost(self,\
     connector, reason)

def clientConnectionFailed(self, connector, reason):
    self.continueTrying = None

    log.msg('Connection failed. Reason: ', reason)
    ReconnectingClientFactory.clientConnectionFailed(self,\
     connector, reason)

ClientProtocol是我的协议。你知道吗

class ClientProtocol(AMP):

def __init__(self, CONNECTION_INFO, gsi):
    self.CONNECTION_INFO = CONNECTION_INFO
    self.gsi = gsi

    log.msg('he pasado por el __init_- de ClientProtocol')

def connectionMade(self):
    self.user_login()
    self.gsi.connectProtocol(self)

def connectionLost(self, reason):
    log.err("Connection lost")
    log.err(reason)
    self.gsi.disconnectProtocol()

@inlineCallbacks
def user_login(self):        
    try:
        res = yield self.callRemote(Login,\
         sUsername=self.CONNECTION_INFO['username'],\
          sPassword=self.CONNECTION_INFO['password'])
        log.msg(res)
        res = yield self.callRemote(StartRemote,\
         iSlotId=self.CONNECTION_INFO['slot_id'])
        log.msg(res)
    except Exception as e:
        log.err(e)
        reactor.stop()

def processFrame(self, frame):

    log.msg('Received frame: ' + frame)
    res = yield self.callRemote(SendMsg, sMsg=frame,\
     iTimestamp=misc.get_utc_timestamp())

    log.msg(res)

如何从对象gsi调用函数procuresframe? 此对象属于另一个模块。你知道吗

我试图用decorator@staticmethod创建一个调用,但它无法识别callRemote方法,尽管对象gsi是从ClientProtocol继承的。你知道吗

如果有任何帮助,我将不胜感激。你知道吗


Tags: 对象方法selfinfologconnectordefres

热门问题