Protocols

Twisted is a network framework that implements a large number of protocols. It uses the paradigm known as event-driven programming, where the flow of a program is determined by the events that occur during its execution. The main objective of this framework is to provide a solution to the problems that are established by the use of sockets at a low level, mediating with threads and with the problems that this also presents (for example, access to shared data).

Twisted implements a multitude of protocols that we can use in our applications in a simple and asynchronous way—it contains a web server, instant messaging clients, chat servers, mail servers and clients, servers and SSH clients, and much more.

Twisted is designed to separate the logical protocols (SMTP, HTTP, and SSH) and transport in physical layers (sockets or SSL). The connection between protocols and layers takes place at the last moment just before the data is delivered to the logical protocol instance. It is at that moment when the protocol layer can make use of the transport layer, that is, as long as they are semantically compatible.

Twisted is responsible for reading data through the protocol that it integrates with the protocol.Protocol class, which is from the twisted.internet package.

The most common use of Twisted is for the definition of the type protocol, which is used from a Twisted factory. It is responsible for managing connections. Finally, we use a reactor object to establish the endpoint of the factory.

Objects of the protocol type are non-persistent, which means that they are created and destroyed after each connection, while a factory is an object with a state where the information is kept between several connections.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset