我跟隨Twisted tutorial和那篇文章嘗試下面的代碼:爲什麼在這個Twisted示例中telnet工作和netcat失敗?
# Read username, output from non-empty factory, drop connections
from twisted.internet import protocol, reactor
from twisted.protocols import basic
class FingerProtocol(basic.LineReceiver):
def lineReceived(self, user):
self.transport.write(self.factory.getUser(user)+"\r\n")
self.transport.loseConnection()
class FingerFactory(protocol.ServerFactory):
protocol = FingerProtocol
def __init__(self, **kwargs):
self.users = kwargs
def getUser(self, user):
return self.users.get(user, "No such user")
reactor.listenTCP(1079, FingerFactory(moshez='Happy and well'))
reactor.run()
我試圖nc localhost 1079
,它只是掛起:無回覆。但後來telnet localhost 1079
工作得很好。爲什麼?
這是100%正確的答案,所以你應該接受你自己的答案:) – Glyph
該網站要求我等兩天才能這樣做。 :) – Fixee