Jython中的SSL服务器[python代码,java库?]

时间:2013-02-26 12:09:06

标签: java python ssl jython

我需要一个支持SSL的服务器(只是一个套接字)的基本工作示例。刚回来“你好世界”就够了:) 障碍是它应该在jython中工作,而AFAIK jython对python的本机ssl库的支持非常有限。所以我假设使用java库是必要的。你能给我一些例子,类似于原始的python:

import socket, ssl
from array import array

resp = 'hello world'

def deal_with_client(connstream):

    connstream.send(resp)

# MAIN part
s = socket.socket()
host = '127.0.0.1'
port = 7001

s.bind((host, port))
s.listen(5)

while True:
    c, addr = s.accept()
    print( "Got Connection From ", addr)
    connstream = ssl.wrap_socket(c,
                             server_side=True,
                             certfile="cert.pem",
                             keyfile="cert.pem",
                             ssl_version=ssl.PROTOCOL_TLSv1)
    try:
        deal_with_client(connstream)
    finally:
        connstream.shutdown(socket.SHUT_RDWR)
        connstream.close()
c.close()

0 个答案:

没有答案