telnet2screen.py

"""Receive text from telnet clients
   and print it to the screen.
   by stephan)
"""
from slut import *
from random import randint
from slut.net import TcpServer
from twisted.protocols.basic import LineReceiver


class Atlantis(World):
    def onSetup(self):
        self.name = "RJ45 Plugs Are Awesome"
        tt = TagText(self, 'nettag', 16)
        tt.setText('Telnet to port 4114 on this machine and start typing.')
        tt.setColor(1.0,1.0,1.0,0.6)
        tt.moveTo(0, 150)
        self.tcpserver = TcpServer(4114, SimpleServer)


class SimpleServer(LineReceiver):
    def connectionMade(self):
        print 'connection established'

    def lineReceived(self, line):
        print 'line received: ', line
        if line == 'q':
            self.transport.loseConnection()
        else:
            glo.world.tags['nettag'].setText(line)
            glo.world.tags['nettag'].moveTo(SineTween(
                randint(0, 300),randint(20, 400), randint(50, 500)/100.0))
            self.write('got it')

    def connectionLost(self, reason):
        print 'connection lost: ', reason

    def write(self, line):
        if self.connected:
            self.sendLine(line)


atlantis = Atlantis()
atlantis.run()
Initiated by Stephan Hechenberger
Thanks to CADRE's 103