[Twisted-Python] twisted ssl server and client
John Aherne
johnaherne at rocs.co.uk
Fri Nov 7 06:14:10 MST 2014
Thanks for the reply.
In the end I took the examples in the docs and changed them to fit.
So I have ended up with something that seems to work.
But I wouldn't mind if someone can tell me if what I have done is miles
wrong or spot on or could do with improvement or you have missed the point
completely.
Thanks for any pointers
Below is the code with simple changes made
#!/usr/bin/env python
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
echoserv_ssl.py
import sys
from twisted.internet import reactor, ssl, protocol, task, defer
from twisted.python import log
import echoserv
log.startLogging(sys.stdout)
#certificate = ssl.PrivateCertificate.loadPEM(certData)
certificate2 =
ssl.DefaultOpenSSLContextFactory('d:\\openssl\\ibook\\ibookservernp.key',
'd:\\openssl\\ibook\\7044921f82b7.crt')
print 'CERT2', certificate2
my_context2 = certificate2.getContext()
my_context2.load_verify_locations('d:\\openssl\\ibook\\gd_bundle-g2-g1.crt')
factory = protocol.Factory.forProtocol(echoserv.Echo)
print 'CERT OPTIONS', dir(certificate2)
reactor.listenSSL(8000, factory, certificate2)
echoserv.py
#!/usr/bin/env python
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor
### Protocol Implementation
# This is just about the simplest possible protocol
class Echo(Protocol):
def dataReceived(self, data):
"""
As soon as any data is received, write it back.
"""
print 'MESSAGE', data
self.transport.write(data) #'HELLO THERE?\r\n')
def main():
f = Factory()
f.protocol = Echo
reactor.listenTCP(8000, f)
reactor.run()
if __name__ == '__main__':
main()
--
*John Aherne*
*www.rocs.co.uk <http://www.rocs.co.uk>*
020 7223 7567
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20141107/a1202f31/attachment-0002.html>
More information about the Twisted-Python
mailing list