Websockets HTML5

I’ve been digging deeper into my original websocket example and I am now very close to a fully functional cross platform websocket solution for Defold.

First of all and most importantly: Emscripten will create websockets automatically when you open sockets. This means that my original example will fail on HTML5 since the whole handshake and encode and decode of websocket frames will be handled by emscripten.

Second: Getting non-blocking sockets to work, regardless of platform is tricky. When setting the socket timeout to 0 you can get timeouts when connecting, sending and receiving data on a socket. You need to handle this in a good way, and I’ve found that it is best handled by using coroutines and yielding while waiting for connection or when reading/writing data.

Finally: I have updated my original example with a fully working cross platform websocket client.

5 Likes