Home > database >  Socket.IO https/ssl in iOS and Python App Engine
Socket.IO https/ssl in iOS and Python App Engine

Time:07-22

I've built an GCP App Engine service in Python 3.7 using Flask and an iOS app in Swift.. the apps are using Socket.IO to connect and transfer data.

Everything works great with a local deployment, however when deploying to GCP the SocketIO connection is never upgraded to a socket and is left defaulting to long polling.

This seems to be an issue with ssl / https, though hours of googling have brought me absolutely no joy. There just isn't sufficient documentation on what i'm supposed to add to get https working over the socket.

The code in my opinion is fairly unremarkable, but here it is anyway

App Engine

app = Flask(__name__)
app.config["SECRET_KEY"] = socket_secret
socketio = SocketIO(app, cors_allowed_origins="*", pingTimeout=60000)

@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
    }()

I'm assuming I need to know two things...

  1. How to create an SSL cert on my App Engine and give it to my Python Socket.io instance
  2. How the SocketManager on iOS uses the cert in the same way cert pinning works over NSURLConnection

CodePudding user response:

If this is Standard env, it could be due to the fact that Standard env doesn't support websockets. See documentation, Google group discussion

See feature request

  • Related