Learning Python Networking - Second Edition
by José Manuel Ortega, Dr. M. O. Faruque Sarker, Sam Washington
Reactor
Twisted implements the reactor design pattern, which describes how to obtain and redirect events from multiple sources to their respective handlers in a single thread.
The Twisted core is the reactor event loop. The event loop waits for these events and then processes them, abstracting specific behavior of a platform and presenting interfaces to facilitate the response.
The reactor is the main Twisted loop, and is responsible for calling the events at the appropriate time and alternating between the different connections to achieve (rather than simulate) concurrency.
For creating a reactor that's listening in a specific port, we can use the listenTCP() method. We will pass in the port and the Factory class that was created in the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access