[Twisted-Python] Using service.Application
Richard.Townsend at edl.uk.eds.com
Richard.Townsend at edl.uk.eds.com
Mon Dec 15 05:14:44 EST 2003
I had the following demo script for Twisted 1.0.6:
#-----------------
import sys
from twisted.internet import app, reactor
from twisted.python import log, logfile
from twisted.web import server, resource
class Simple(resource.Resource):
isLeaf = True
def render(self, request):
print "Request:", request
return "<html>Hello</html>"
if __name__ == '__main__':
f = sys.stdout
log.startLogging(f)
site = server.Site(Simple())
application = app.Application('web')
application.bindPorts()
application.listenTCP(8080, site)
application.run(save=0)
#-----------------
This works OK with the following client:
#-----------------
from twisted.internet import reactor
from twisted.web.client import getPage
from twisted.python.util import println
class Client:
def __init__(self):
self.sendReq()
reactor.run()
def handleCallback(self, value):
println("Success:", value)
reactor.stop()
def handleErrback(self, error):
println("Error:", error)
reactor.stop()
def sendReq(self):
uri = "http://localhost:8080/Simple"
deferred = getPage(uri)
deferred.addCallbacks(self.handleCallback,
self.handleErrback)
if __name__ == "__main__":
Client()
#-----------------
However, under Twisted 1.1.1 this raises:
exceptions.DeprecationWarning: twisted.internet.app is deprecated,
use twisted.application instead.
So I tried to create a new version of the server:
#-----------------
import sys
from twisted.application import service, internet
from twisted.internet import reactor
from twisted.python import log
from twisted.web import server, resource
class Simple(resource.Resource):
isLeaf = True
def render(self, request):
print "Request:", request
return "<html>Hello</html>"
if __name__ == '__main__':
f = sys.stdout
log.startLogging(f)
root = Simple()
site = server.Site(root)
application = service.Application('web')
sc = service.IServiceCollection(application)
i = internet.TCPServer(8080, site)
i.setServiceParent(sc)
reactor.run()
#-----------------
But now my client gives this:
Error: [Failure instance: Traceback:
twisted.internet.error.ConnectionRefusedError,
Connection was refused by other side: 22: Invalid argument.
]
I am running Python 2.3.2 on HP-UX 11i.
Can anybody advise what is happening here?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20031215/a6b7954a/attachment.htm
More information about the Twisted-Python
mailing list