2016-09-09 75 views
0

我想通過HTTPS運行以下的eventlet WSGI服務器。我正嘗試從支持HTTPS的Web服務器上的JavaScript連接到python服務器。如何通過HTTPS運行python-socketio(eventlet WSGI服務器)

我想回答下面的描述,我將如何更改下面的代碼以使用HTTPS。

import socketio 
import eventlet 
import eventlet.wsgi 
from flask import Flask, render_template 

sio = socketio.Server() 
app = Flask(__name__) 

@app.route('/') 
def index(): 
    """Serve the client-side application.""" 
    return render_template('index.html') 

@sio.on('connect', namespace='/chat') 
    def connect(sid, environ): 
    print("connect ", sid) 

@sio.on('chat message', namespace='/chat') 
def message(sid, data): 
    print("message ", data) 
    sio.emit('reply', room=sid) 

@sio.on('disconnect', namespace='/chat') 
def disconnect(sid): 
    print('disconnect ', sid) 

if __name__ == '__main__': 
    # wrap Flask application with engineio's middleware 
    app = socketio.Middleware(sio, app) 

    # deploy as an eventlet WSGI server 
    eventlet.wsgi.server(eventlet.listen(('', 8000)), app) 

此代碼是從here

回答

0

採取要運行Evenlet WSGI服務器通過HTTPS所有的需要是將SSL包裹的插座傳遞給服務器()方法,如下所示:

wsgi.server(eventlet.wrap_ssl(eventlet.listen(('', 8000)), 
          certfile='cert.crt', 
          keyfile='private.key', 
          server_side=True), 
     app) 
相關問題