[Twisted-Python] Throttling Factory Problem ...
Joël Vennin
joel.vennin at wanadoo.fr
Sun Jul 20 05:46:14 MDT 2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello all,
I'm making an example to limit bandwidth with ThrottlingFactory. I've a server
and a client. Client and server make echo. So it's an infinite process. I've
limited the bandwith to 1Ko/s.
The problem is that the client send a lot's of data (more than the limited
bandwidth) during a little time. The server get all the data (more than the
limited bandwith) and after each wait a long of time before send/received
something.
Maybe i miss something, can you help me.
Thank you, jol
client.py:
from twisted.protocols import policies
from twisted.internet import protocol, reactor
class SenderProtocol(protocol.Protocol):
def connectionMade(self):
self.transport.registerProducer (self, 1)
self.sendSomething ()
def pauseProducing(self):
print "Sender Protocol make a Pause"
def resumeProducing(self):
print "Sender Protocol make a Resume"
def stopProducing(self):
pass
def sendSomething (self):
self.transport.write (500 * "c")
def dataReceived(self, data):
self.transport.write(data)
class Client(protocol.ClientFactory):
protocol = SenderProtocol
client = Client()
tClient = policies.ThrottlingFactory(client, readLimit=1000)
#port = reactor.listenTCP (7000, tServer, interface="127.0.0.1")
port = reactor.connectTCP ("127.0.0.1", 7000, tClient)
reactor.run ()
server.py:
from twisted.protocols import policies
from twisted.internet import protocol, reactor
class EchoProtocol(protocol.Protocol):
def connectionMade(self):
self.transport.registerProducer (self, 1)
def pauseProducing(self):
print "Echo Protocol make a Pause"
def resumeProducing(self):
print "Echo Protocol make a Resume"
def stopProducing(self):
pass
def dataReceived(self, data):
self.transport.write(data)
class Server(protocol.ServerFactory):
protocol = EchoProtocol
server = Server()
tServer = policies.ThrottlingFactory(server, writeLimit=1000, readLimit=1000)
port = reactor.listenTCP (7000, tServer, interface="127.0.0.1")
reactor.run ()
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQE/GoEJOzJ7itUoJpQRAgHgAJ9uDoy6Rj13J4mNC1PUp/GbhDMoWACdGv5/
KO7Hj3TchnGjizz3tM5l9jw=
=swOH
-----END PGP SIGNATURE-----
More information about the Twisted-Python
mailing list