Java知识分享网 - 轻松学习从此开始!    

Java知识分享网

Java1234官方群25:java1234官方群17
Java1234官方群25:838462530
        
SpringBoot+SpringSecurity+Vue+ElementPlus权限系统实战课程 震撼发布        

最新Java全栈就业实战课程(免费)

springcloud分布式电商秒杀实战课程

IDEA永久激活

66套java实战课程无套路领取

锋哥开始收Java学员啦!

Python学习路线图

锋哥开始收Java学员啦!
当前位置: 主页 > Java文档 > Java基础相关 >

The Twisted Documentation PDF 下载


分享到:
时间:2020-09-22 09:03来源:http://www.java1234.com 作者:转载  侵权举报
The Twisted Documentation PDF 下载
失效链接处理
The Twisted Documentation PDF 下载


本站整理下载:
 
相关截图:
 
主要内容:

Introduction
1.1 The Vision For Twisted
Many other documents in this repository are dedicated to defining what Twisted is. Here, I will attempt to explain not
what Twisted is, but what it should be, once I’ve met my goals with it.
First, Twisted should be fun. It began as a game, it is being used commercially in games, and it will be, I hope, an
interactive and entertaining experience for the end-user.
Twisted is a platform for developing internet applications. While Python by itself is a very powerful language,
there are many facilities it lacks which other languages have spent great attention to adding. It can do this now;
Twisted is a good (if somewhat idiosyncratic) pure-python framework or library, depending on how you treat it, and it
continues to improve.
As a platform, Twisted should be focused on integration. Ideally, all functionality will be accessible through
all protocols. Failing that, all functionality should be configurable through at least one protocol, with a seamless
and consistent user-interface. The next phase of development will be focusing strongly on a configuration system
which will unify many disparate pieces of the current infrastructure, and allow them to be tacked together by a nonprogrammer.
Chapter 2
Getting Started
2.1 Writing Servers
2.1.1 Overview
This document explains how you can use Twisted to implement network protocol parsing and handling for TCP servers
(the same code can be reused for SSL and Unix socket servers). There is a separate document (page 125) covering
UDP.
Your protocol handling class will usually subclass twisted.internet.protocol.Protocol. Most protocol handlers inherit either from this class or from one of its convenience children. An instance of the protocol class is
instantiated per-connection, on demand, and will go away when the connection is finished. This means that persistent
configuration is not saved in the Protocol.
The persistent configuration is kept in a Factory class, which usually inherits from twisted.internet.
protocol.Factory. The buildProtocol method of the Factory is used to create a Protocol for each
new connection.
It is usually useful to be able to offer the same service on multiple ports or network addresses. This is why the
Factory does not listen to connections, and in fact does not know anything about the network. See the endpoints documentation (page 158) for more information, or twisted.internet.interfaces.IReactorTCP.listen
TCP, and the other IReactor*.listen* APIs for the lower level APIs that endpoints are based on.
This document will explain each step of the way.
2.1.2 Protocols
As mentioned above, this, along with auxiliary classes and functions, is where most of the code is. A Twisted protocol
handles data in an asynchronous manner: the protocol responds to events as they arrive from the network; the events
arrive as calls to methods on the protocol.
Here is a simple example:
from twisted.internet.protocol import Protocol
class Echo(Protocol):
def dataReceived(self, data):
self.transport.write(data)
This is one of the simplest protocols. It simply writes back whatever is written to it, and does not respond to all
events. Here is an example of a Protocol responding to another event:
from twisted.internet.protocol import Protocol
class QOTD(Protocol):
def connectionMade(self):
self.transport.write("An apple a day keeps the doctor away\r\n")
self.transport.loseConnection()

 

------分隔线----------------------------

锋哥公众号


锋哥微信


关注公众号
【Java资料站】
回复 666
获取 
66套java
从菜鸡到大神
项目实战课程

锋哥推荐