rendered paste body#!/usr/bin/python
from twisted.internet import protocol, reactor
from twisted.protocols import basic
from threading import Timer
class RTPUpdateProtocol(basic.LineReceiver):
def __init__(self):
self.delimiter = '\n'
def connectionMade(self):
global generator
generator = self
print_summut()
def lineReceived(self, command):
command.strip('\n')
print "Got: %s" % command
class RTPUpdateFactory(protocol.ServerFactory):
protocol = RTPUpdateProtocol
def print_summut():
global generator
if generator is not None:
generator.transport.write("PING\n")
print "sent PING"
t = Timer(1, print_summut)
t.start()
# Initialisation
generator = None
reactor.listenTCP(5002, RTPUpdateFactory(), 5, "127.0.0.1")
reactor.run()