我使用 Flask 在 Python 3.7 中構建了一個 GCP App Engine 服務,并在 Swift 中構建了一個 iOS 應用程式。這些應用程式使用 Socket.IO 來連接和傳輸資料。
在本地部署中一切都很好,但是在部署到 GCP 時,SocketIO 連接永遠不會升級到套接字,并且默認為長輪詢。
這似乎是 ssl / https 的問題,盡管數小時的谷歌搜索完全沒有給我帶來快樂。沒有足夠的檔案說明我應該添加什么以使 https 在套接字上作業。
我認為代碼相當不起眼,但無論如何都在這里
應用引擎
app = Flask(__name__)
app.config["SECRET_KEY"] = socket_secret
socketio = SocketIO(app, cors_allowed_origins="*")
@socketio.event()
def connect():
print("******* connection established *******")
@socketio.on("update")
def update(json):
handle_update(json)
if __name__ == '__main__':
print("Starting")
socketio.run(app, debug=True)
iOS
private lazy var socketManager: SocketManager = {
let config: SocketIOClientConfiguration = [.log(true),
.compress,
//.connectParams(["ssl_verify": false]),
//.forceWebsockets(true)
]
let manager = SocketManager(socketURL: URL(string: domain)!, config: config)
return manager
}()
我假設我需要知道兩件事...
- 如何在我的 App Engine 上創建 SSL 證書并將其提供給我的 Python
Socket.io
實體 - iOS 上如何以
SocketManager
與證書固定相同的方式使用證書NSURLConnection
uj5u.com熱心網友回復:
如果這是標準環境,可能是因為標準環境不支持 websockets。見檔案,谷歌小組討論
查看功能請求
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/507771.html
標籤:Google Cloud Collective Python IOS ssl 谷歌应用引擎 套接字.io