⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shoutclient.py

📁 大型多人在线游戏开发,该书光盘上附带的源码
💻 PY
字号:
from twisted.internet.protocol import Protocol, ClientFactoryclass Shout(Protocol):             # Class designed to manage a connection.    stringToShout = "Twisted is great!" # a string to send the echo server    def connectionMade(self):      # Method called when connection established.        self.buf = ""              # create an empty buffer        print "Shouting:", repr(self.stringToShout)        self.transport.write(self.stringToShout)    def dataReceived(self, data):  # Method called when data is received.        self.buf += data           # buffer any received data        if self.buf == self.stringToShout: # if we've received the full message            self.transport.loseConnection() # then close the connection.            print "Echoed:", repr(self.stringToShout)            reactor.stop()class ShoutClientFactory(ClientFactory):    def buildProtocol(self, address):        return Shout()              # Build Protocols on incoming connectionsfrom twisted.internet import reactor# connect to local port 1234 and expect an echo.reactor.connectTCP("localhost", 1234, ShoutClientFactory())reactor.run() # run the main loop until the user interrupts it

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -