Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between twisted.protocols.basic.LineReceiver and twisted.internet.protocol.Protocol?

For a typical client-server based application, how do the two differ from each other. Specifically, what is special with a line-based protocol? Even better, when does a class have to inherit from Protocol and when from LineReceiver?

like image 841
gravetii Avatar asked Oct 28 '25 02:10

gravetii


1 Answers

Difference becomes by received data handling.

Protocol have dataReceived function. It will be called whenever data received.

LineReceiver overrides Protocol. It is implements a basic messaging format that messages separated with ' \r\n'.

Let's assume server writes messages like;

request.write("Lorem ipsum")
request.write("do amet siempre.\r\n")
request.write("We have Drogba!\r\n")

Messaged received on the Client side with implements Protocol;

def dataReceived(self, data):
   print data
.
.
output:

Lorem ipsum
do amet siempre.
We have Drogba!

Messaged received on the Client side with implements LineReceiver;

def lineReceived(self, line):
   print line
.
.
output: 
Lorem ipsum do amet siempre.
We have Drogba!

I hope it is helpful. For more information you can look reference or comment to ask.

like image 54
cengizkrbck Avatar answered Oct 30 '25 17:10

cengizkrbck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!