[myhaspl@iZ23mdqdp94Z ~]$ cat learn/l1/myserver.pl
from twisted.internet.protocol import Protocol
from twisted.internet import reactor
from twisted.internet.protocol import Factory
from twisted.internet.endpoints import TCP4ServerEndpoint
class Echo(Protocol):
def dataReceived(self,data):
self.transport.write(data)
class EchoFactory(Factory):
def buildProtocol(self,addr):
return Echo()
endpoint=TCP4ServerEndpoint(reactor,8001)
endpoint.listen(EchoFactory())
reactor.run()
27747 pts/0 00:00:00 ps
Type `help' to learn how to use Xshell prompt.
本地客户端远程telnet测试
[c:\~]$ telnet 120.55.x.x 8001python
服务器上telnet测试
[myhaspl@iZ23mdqdp94Z l1]$ telnet 127.0.0.1 8001
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
hello,world
hello,world
hi
hi