Twisted のサンプル チャット サーバーに大まかに基づいたサーバーがあります。telnetで動作します。ここで、クライアントを接続する必要があります。サンプルのワンタイム クライアントをコピーしました。問題は、サーバーが「会話」を開始するはずの「hello」文字列を受信しないことです。FAQ でよくある間違いはリアクターの実行をブロックすることだと読みましたが、以下のコードのどこでそれを行うことができるかわかりません。誰が何が悪いのか教えてもらえますか?
from twisted.internet import reactor
from twisted.internet.protocol import Factory, Protocol
from twisted.internet.endpoints import TCP4ClientEndpoint
class Greeter(Protocol):
def sendMessage(self, msg):
self.transport.write("%s\n" % msg)
class GreeterFactory(Factory):
def buildProtocol(self, addr):
return Greeter()
def gotProtocol(p):
p.sendMessage("hello")
reactor.callLater(1, p.sendMessage, "/p2")
reactor.callLater(2, p.transport.loseConnection)
point = TCP4ClientEndpoint(reactor, "localhost", 8123)
d = point.connect(GreeterFactory())
d.addCallback(gotProtocol)
reactor.run()