Websocket problem

I did some more research and as was pointed out in the linked post you can’t connect using a normal socket. A WebSocket requires a handshake and more things to get it set up properly. Luckily there’s a lua-websocket project on GitHub that with some modifications can be made to work with Defold.

I’ve put together a minimal example of a WebSocket client connecting to an echo server and sending and receiving data. Note that this implementation uses the synchronous version of lua-websocket. I couldn’t get the copas based version to work. It should however be fairly easy to roll your own async version using coroutines. I put the code here:

4 Likes