0

我正在使用 Twisted Documentation Finger 教程 ( http://twistedmatrix.com/documents/current/core/howto/tutorial/intro.html ) 为我正在从事的项目学习 Twisted 框架,但我无法获得我的程序工作。

这是服务器的代码,它应该在我返回“没有这样的用户”时telnet localhost 12345,但它只是停留在那里,没有发生任何事情。

from twisted.internet import protocol, reactor
from twisted.protocols import basic

class FingerProtocol(basic.LineReceiver):
    def lineReceived(self, user):
        self.transport.write("No such user\r\n")
        self.transport.loseConnection()

class FingerFactory(protocol.ServerFactory):
    protocol = FingerProtocol

reactor.listenTCP(12345, FingerFactory()) 
reactor.run()

我已经通过python twisted-finger.pyand运行了服务器sudo python twisted-finger.py,但都没有工作。

有谁知道为什么这不会返回它应该返回的消息?

4

1 回答 1

3

您必须在服务器响应之前向服务器发送手指请求。

根据手指 rfc

Send a single "command line", ending with <CRLF>.

The command line:

    Systems may differ in their interpretations of this line.  However,
    the basic scheme is straightforward:  if the line is null (i.e. just
    a <CRLF> is sent) then the server should return a "default" report
    which lists all people using the system at that moment.  If on the
    other hand a user name is specified (e.g. FOO<CRLF>) then the
    response should concern only that particular user, whether logged in
    or not.

尝试在 telnet 中输入一个单词并按回车键。

于 2013-12-16T19:16:12.733 回答