【问题标题】:Learning the Twisted framework and having trouble with the finger server学习 Twisted 框架并遇到手指服务器问题
【发布时间】:2013-12-16 18:32:41
【问题描述】:

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

这是服务器的代码,当我telnet localhost 12345 时它应该返回“No such User”,但它只是停留在那里,没有任何反应。

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.pysudo python twisted-finger.py 运行了服务器,但都没有成功。

有谁明白为什么这没有返回它应该返回的消息?

【问题讨论】:

    标签: python-2.7 twisted twisted.internet


    【解决方案1】:

    您必须先向服务器发送一个手指请求,然后它才会响应。

    根据finger 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 中输入一个单词并按回车键。

    【讨论】:

    • 非常感谢!这解决了我的问题,这是有道理的,因为我遇到了与之前类似的事情(D-OH)谢谢!
    猜你喜欢
    • 2015-03-27
    • 1970-01-01
    • 1970-01-01
    • 2014-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多