我学习网络编程与o'REilys扭曲网络编程基本指南(使用pyde)
我有两个问题:pycharm中没有识别函数maybeStopReactor(),而QuoteClientFactory没有被视为已定义的类
我怎样才能找到解决办法呢
class QuoteClientFactory(protocol.ClientFactory):
def __init__(self, quote):
self.quote = quote
def buildProtocol(self, addr):
return QuoteProtocol(self)
def clientConnectionFailed(self, connector, reason):
print("connecton failed:"), reason.getErrorMessage()
**maybeStopReactor()**
def clientConnectionLost(self, connector, reason):
print("connection lost"), reason.getErrorMessage()
maybeStopReactor()
def maybeStopReactor(self):
global quote_counter
quote_counter -=1
if not quote_counter:
reactor.stop()
quotes = [
"you snooze you lose",
"The early bird gets the worm",
"carpe diem"
]
quote_counter = len(quotes)
for quote in quotes:
**reactor.connectTCP('localhost', 6942, QuoteClientFactory(quote))**
reactor.run()
你的压痕不对。这有点难看,因为代码跨越了一个分页符。你想要的是:
相关问题 更多 >
编程相关推荐