Twisted is an event-driven network framework that includes features such as network Protocols, threading, database management, network operations, e-mail, and more.
Twisted Introduction: http://blog.csdn.net/hanhuili/article/details/9389433
Event-driven
In short, the event driver is divided into two parts: first, registering the event; second, triggering the event.
Custom event-driven framework named: "Kill the Gentleman":
#!/usr/bin/env python#-*-coding:utf-8-*- #event_drive.pyevent_list= [] defrun (): forEventinchEvent_list:obj=event () Obj.execute ()classBasehandler (object):"""the user must inherit the class to standardize the methods of all classes (similar to the functionality of the interface)""" defExecute (self): #必须重写此方法, error if not writtenRaiseException ('You must overwrite execute') The best event-driven framework
Programmers use the "kill the Gentleman Frame":
# !/usr/bin/env python # -*-coding:utf-8-*- from Import event_drive class MyHandler (event_drive. Basehandler): def execute (self): print' Event-drive Execute MyHandler' event_drive.event_list.append (MyHandler) Event_ Drive.run ()
Protocols
Protocols describes how to handle events in a network asynchronously. HTTP, DNS, and IMAP are examples of application-layer protocols. Protocols implements the Iprotocol interface, which contains the following methods:
MakeConnection establish a connection between the transport object and the server
Called after the Connectionmade connection is established.
DataReceived call when receiving data
Connectionlost call when closing a connection
Transports
Transports represents the connection between two communication nodes in a network. Transports is responsible for describing the details of the connection, such as whether the connection is flow-oriented or datagram-oriented, flow control, and reliability. TCP, UDP, and UNIX sockets can be used as examples of transports. They are designed to "satisfy the smallest functional unit with maximum reusability" and are separated from the protocol implementation, which allows many protocols to take the same type of transmission. Transports implements the Itransports interface, which contains the following methods:
Write writes data to a physical connection sequentially, in a non-blocking fashion
Writesequence writes a list of strings to a physical connection
Loseconnection writes all pending data and then closes the connection
Getpeer obtaining address information in the peer-to-peer connection
GetHost get the address information of the local side of the connection
Separating the transports from the protocol makes it easier to test these two levels. The transmission can be simulated by simply writing a string, which is checked in this way.
twsited Asynchronous Network Framework