Search code examples
python-2.7twistedtwisted.internet

Learning the Twisted framework and having trouble with the finger server


I am learning the Twisted framework for a project I am working on by using the Twisted Documentation Finger tutorial (http://twistedmatrix.com/documents/current/core/howto/tutorial/intro.html) and I'm having trouble getting my program to work.

Here's the code for the server, it should return "No Such User" when I telnet localhost 12345, but it just stays there, nothing happening.

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()

I have run the server via python twisted-finger.py and sudo python twisted-finger.py, but neither worked.

Does anyone see why this doesn't return the message it is supposed to?


Solution

  • You have to send a finger request to the server before it responds.

    According to the 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.
    

    Try typing a word into telnet and hitting enter.