Defold-WebSocket (DEPRECATED)

How to do it? I’m new. I thought that I installed the extension and use it :slight_smile:

Please add the githab guide to the readme. It is useful to many, since without crutches in any way.

Here you go: https://github.com/britzl/defold-websocket#how-to-connect-using-a-secure-web-socket-wss

2 Likes

Thanks! Works! :slight_smile:

1 Like

Hello!
Does not work on the android (USB modem and wi-fi too)


MacOS Mojave 10.14.5
Android 9.0 (Asus Zenfone M1)

How are you testing on mobile? I’m guessing that you’ve downloaded dmengine.apk, installed that and target it? This won’t work. The Defold-Websocket library uses a native extension, meaning that it contains native code that needs to be compiled into a custom engine for you. You must bundle a debug version and install it and target that version while you iterate on your game.

wow… where can I read about it?

I have now tried your code on html5 - it does not work (

Where can you read about what? How to bundle for mobile?

This is mentioned here: https://github.com/britzl/defold-websocket/blob/master/README.md#important-note-on-sec-websocket-protocol-and-chrome

If you try on a websocket server of your own or something like Colyseus it will work as expected.

1 Like

I use websockets in about 10 html5 projects, including Corona SDK (html5). Problems with Sec-WebSocket-Protocol never existed.

Crash even when using my server, for example wss://words.webday.ru/wsm

How can I prevent the transfer of the protocol in html if I do not want to specify it? This is an optional parameter. If I use any protocol, but in html5 the value is still “binary”

By the way, for some reason, in the example, instead of the protocol, you specify: ws / wss

Headers:
From HTML5

From defold simulator (macos)

On the server I use the most popular solution for nodejs: https://www.npmjs.com/package/ws
There have never been any problems

Let me take a look at this again and see if anything can be done.

Yes, that’s how it is supposed to work:

But then there is confusion. Through the simulator headers = ws / wss / nil.
And through html always = binary

Yes, I understand the confusion. This is how it works:

  • On desktop and mobile we have socket connections using LuaSocket built into the engine. In order to support the WebSocket protocol we need functionality to upgrade the socket connection to a WebSocket connection. This is done by lua-websocket on which defold-websocket is based. So basically all of the Lua code in the project comes from lua-websocket and it is there to support WebSocket connections on desktop and mobile.
  • On HTML5 however there is no such thing as a socket. You can make HTTP requests and you can create WebSockets. When you create a TCP socket connection in an HTML5 build it will automatically be upgraded to a WebSocket. This is done by Emscripten (and Websockify). And that is why you find two different code-paths throughout the client_async.lua file. And it is the Emscripten WebSocket connection that sets the Sec-Websocket-Protocol to “binary”.
    • We can maybe fix this by building using some other compiler flags or build parameters but I’m not sure about this.
5 Likes

Hello!
What about support of arm64-android platform for this extension? There are problem with defold-luasec dependency.

1 Like

This is about another extension (defold-luasec), perhaps it’s possible to enable issues on that fork, @britzl?

I checked my server returns in the headers “binary” too. But crash happens anyway

even has time to accept the message, but breaks off

That is, with a handshake, everything is fine! But when receiving a message = crash

1 Like

I’ve released a new version of luasec with openssl compiled for arm-64: https://github.com/britzl/defold-luasec/releases/tag/1.1.0

3 Likes

Strange. @selimanac and @endel have you been able to connect from an HTML5 Defold client to a Colyseus server?

I just build tic-tac example as html5 and test it on my local environment. Seems like it is working. To be honest, I didn’t understand the problem here.

1 Like

The Colosseum transmits binary data. That is why it works. And I pass in all my projects = string (json), like most of the developers who use web sockets.

Is it possible to somehow choose other data types? Web socket capabilities are limited in this view.

my:

1 Like