|
700.
|
|
|
Since this verison is reading data from a file (and refreshing the data every 30 seconds), there is no <code>FingerSetterFactory</code> and thus nothing listening on port 1079.
|
|
|
type: Content of: <html><body><p>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
howto/tutorial/protocol.xhtml:102
|
|
701.
|
|
|
Here we override the standard <code class="API" base="twisted.application.service.Service">startService</code> and <code class="API" base="twisted.application.service.Service">stopService</code> hooks in the Finger service, which is set up as a child service of the application in the last line of the code. <code>startService</code> calls <code>_read</code>, the function responsible for reading the data; <code>reactor.callLater</code> is then used to schedule it to run again after thirty seconds every time it is called. <code>reactor.callLater</code> returns an object that lets us cancel the scheduled run in <code>stopService</code> using its <code>cancel</code> method.
|
|
|
type: Content of: <html><body><p>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
howto/tutorial/protocol.xhtml:106
|
|
702.
|
|
|
Announce on Web, Too
|
|
|
type: Content of: <html><body><h2>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
howto/tutorial/protocol.xhtml:118
|
|
703.
|
|
|
The same kind of service can also produce things useful for other protocols. For example, in twisted.web, the factory itself (<code base="API" class="twisted.web.server">Site</code>) is almost never subclassed — instead, it is given a resource, which represents the tree of resources available via URLs. That hierarchy is navigated by <code base="API" class="twisted.web.server">Site</code> and overriding it dynamically is possible with <code base="API" class="twisted.web.resource.Resource">getChild</code>.
|
|
|
type: Content of: <html><body><p>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
howto/tutorial/protocol.xhtml:120
|
|
704.
|
|
|
To integrate this into the Finger application (just because we can), we set up a new TCPServer that calls the <code base="API" class="twisted.web.server">Site</code> factory and retrieves resources via a new function of <code>FingerService</code> named <code>getResource</code>. This function specifically returns a <code base="API" class="twisted.web.resource">Resource</code> object with an overridden <code base="API" class="twisted.web.resource.Resource">getChild</code> method.
|
|
|
type: Content of: <html><body><p>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
howto/tutorial/protocol.xhtml:129
|
|
705.
|
|
|
<a href="listings/finger/finger15.tac" class="py-listing">finger15.tac</a>
|
|
|
type: Content of: <html><body>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
howto/tutorial/protocol.xhtml:137
|
|
706.
|
|
|
Announce on IRC, Too
|
|
|
type: Content of: <html><body><h2>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
howto/tutorial/protocol.xhtml:140
|
|
707.
|
|
|
This is the first time there is client code. IRC clients often act a lot like servers: responding to events from the network. The reconnecting client factory will make sure that severed links will get re-established, with intelligent tweaked exponential back-off algorithms. The IRC client itself is simple: the only real hack is getting the nickname from the factory in connectionMade.
|
|
|
type: Content of: <html><body><p>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
howto/tutorial/protocol.xhtml:142
|
|
708.
|
|
|
<a href="listings/finger/finger16.tac" class="py-listing">finger16.tac</a>
|
|
|
type: Content of: <html><body>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
howto/tutorial/protocol.xhtml:149
|
|
709.
|
|
|
<code>FingerService</code> now has another new function, <code>getIRCbot</code>, which returns the <code>ReconnectingClientFactory</code>. This factory in turn will instantiate the <code>IRCReplyBot</code> protocol. The IRCBot is configured in the last line to connect to <code>irc.freenode.org</code> with a nickname of <code>fingerbot</code>.
|
|
|
type: Content of: <html><body><p>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
howto/tutorial/protocol.xhtml:151
|