<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>Using service.Application</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2>I had the following demo script for Twisted 1.0.6:</FONT>
</P>

<P><FONT SIZE=2>#-----------------</FONT>
<BR><FONT SIZE=2>import sys</FONT>
<BR><FONT SIZE=2>from twisted.internet import app, reactor</FONT>
<BR><FONT SIZE=2>from twisted.python import log, logfile</FONT>
<BR><FONT SIZE=2>from twisted.web import server, resource</FONT>
</P>

<P><FONT SIZE=2>class Simple(resource.Resource):</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; isLeaf = True</FONT>
</P>

<P><FONT SIZE=2>&nbsp;&nbsp;&nbsp; def render(self, request):</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;Request:&quot;, request</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return &quot;&lt;html&gt;Hello&lt;/html&gt;&quot;</FONT>
</P>
<BR>

<P><FONT SIZE=2>if __name__ == '__main__':</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; </FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; f = sys.stdout</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; log.startLogging(f)</FONT>
</P>

<P><FONT SIZE=2>&nbsp;&nbsp;&nbsp; site = server.Site(Simple())</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; application = app.Application('web')</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; application.bindPorts()</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; application.listenTCP(8080, site)</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; application.run(save=0)</FONT>
<BR><FONT SIZE=2>#-----------------</FONT>
</P>

<P><FONT SIZE=2>This works OK with the following client:</FONT>
</P>

<P><FONT SIZE=2>#-----------------</FONT>
<BR><FONT SIZE=2>from twisted.internet import reactor</FONT>
<BR><FONT SIZE=2>from twisted.web.client import getPage</FONT>
<BR><FONT SIZE=2>from twisted.python.util import println</FONT>
</P>
<BR>

<P><FONT SIZE=2>class Client:</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; </FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; def __init__(self):</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.sendReq()</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reactor.run()</FONT>
</P>
<BR>

<P><FONT SIZE=2>&nbsp;&nbsp;&nbsp; def handleCallback(self, value):</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; println(&quot;Success:&quot;, value)</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reactor.stop()</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; </FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; </FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; def handleErrback(self, error):</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; println(&quot;Error:&quot;, error)</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reactor.stop()</FONT>
</P>
<BR>

<P><FONT SIZE=2>&nbsp;&nbsp;&nbsp; def sendReq(self):</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uri = &quot;<A HREF="http://localhost:8080/Simple" TARGET="_blank">http://localhost:8080/Simple</A>&quot;</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; deferred = getPage(uri)</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; deferred.addCallbacks(self.handleCallback,</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.handleErrback)</FONT>
</P>

<P><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT>
<BR><FONT SIZE=2>if __name__ == &quot;__main__&quot;:</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; </FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; Client()</FONT>
<BR><FONT SIZE=2>#-----------------</FONT>
</P>

<P><FONT SIZE=2>However, under Twisted 1.1.1 this raises: </FONT>
<BR><FONT SIZE=2>exceptions.DeprecationWarning: twisted.internet.app is deprecated, </FONT>
<BR><FONT SIZE=2>use twisted.application instead.</FONT>
</P>

<P><FONT SIZE=2>So I tried to create a new version of the server:</FONT>
</P>

<P><FONT SIZE=2>#-----------------</FONT>
<BR><FONT SIZE=2>import sys</FONT>
<BR><FONT SIZE=2>from twisted.application import service, internet</FONT>
<BR><FONT SIZE=2>from twisted.internet import reactor</FONT>
<BR><FONT SIZE=2>from twisted.python import log</FONT>
<BR><FONT SIZE=2>from twisted.web import server, resource</FONT>
</P>
<BR>

<P><FONT SIZE=2>class Simple(resource.Resource):</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; isLeaf = True</FONT>
</P>

<P><FONT SIZE=2>&nbsp;&nbsp;&nbsp; def render(self, request):</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;Request:&quot;, request</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return &quot;&lt;html&gt;Hello&lt;/html&gt;&quot;</FONT>
</P>
<BR>

<P><FONT SIZE=2>if __name__ == '__main__':</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; </FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; f = sys.stdout</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; log.startLogging(f)</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; </FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; root = Simple()</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; site = server.Site(root)</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; application = service.Application('web')</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; sc = service.IServiceCollection(application)</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; i = internet.TCPServer(8080, site)</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; i.setServiceParent(sc)</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; reactor.run()</FONT>
<BR><FONT SIZE=2>#-----------------</FONT>
</P>

<P><FONT SIZE=2>But now my client gives this:</FONT>
</P>

<P><FONT SIZE=2>Error: [Failure instance: Traceback: </FONT>
<BR><FONT SIZE=2>twisted.internet.error.ConnectionRefusedError, </FONT>
<BR><FONT SIZE=2>Connection was refused by other side: 22: Invalid argument.</FONT>
<BR><FONT SIZE=2>]</FONT>
</P>

<P><FONT SIZE=2>I am running Python 2.3.2 on HP-UX 11i.</FONT>
</P>

<P><FONT SIZE=2>Can anybody advise what is happening here?</FONT>
</P>
<BR>

</BODY>
</HTML>