Anyone looked into using socketio on ktor ?
# ktor
s
Anyone looked into using socketio on ktor ?
d
What’s your use-case? Why not using WebSockets directly? Working everywhere except opera mini (<3% of the users, in my country even less: 0.12%): https://caniuse.com/#feat=websockets
s
I am not a big expert of the protocol but I know it handles some stuff with reconnection and maybe also some multiplexing ?
We use it currently so I would just prefer to only replace the server part
d
I understand your point on wanting to keep the client code untouched. Not sure how much websocket.io handles at the backend part, but if the client doesn’t have special conventions, it might work with the ktor server implementation. As far as I am aware, right now you cannot plug an external websocket implementation to the ktor server. Regarding to multiplexing and reconnection. Multiplexing already happens in the way that you can send and receive websocket frames at any point. They will be queued and sent in order asap and received as long as they are read from the socket. Reconnection usually happens at client-side by recreating the object, since WebSocket doesn’t have a reconnect/connect method. There are small decorators for that: https://github.com/joewalnes/reconnecting-websocket Usually reconnection also means persisting the state. There is a sample persisting some state in ktor using a session here: https://github.com/ktorio/ktor-samples/tree/master/app/chat If the websocket.io backend part requires some ceremony, it won’t work at this point. Depending on their implementation and if their implementation can reuse an already opened socket would be possible to modify ktor to allow external websocket implementations. But this would require some time.
s
Right. Thanks. Its a bit unclear how much is handled by the client and server libraries and how much of it we need vs. a raw websocket. It is not entirely clear after reading a bit about it.
👍 1
I suspect it would only require a layer on top of ktor though
m
I don’t think there’s a Socket.io v2 implementation for Java, is there? So if you’re using v2 on the client, I don’t think you’ll be able to use ktor.
269 Views