Defold-WebSocket (DEPRECATED)

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

Pleaaaaaase, add select type :sneezing_face:

I have exact same issue! Any way to fix it?

No :frowning:

Remind me again. What is the problem here? What do you mean by “type” in the context of a WebSocket?

Websockets can take two types, but in this implementation you can send/put only binary data.

In android / ios / simulator - two types
in hmtl5 - only binary! :frowning:

Really needed: STRING!

Can you provide some documentation? Is this the Sec-WebSocket-Protocol header?

In my example provided with defold-websocket I passed the wrong data to ws_protocol. I took a look at the code yesterday and made a minor change to handle this properly:

With this change all but the HTML5 platform allows you to define whatever value to Sec-WebSocket-Protocol in the second argument to self.ws:connect(url, [ws_protocol], [sslparams]).

In HTML5 builds the whole websocket setup is done by Emscripten in which case the Sec-WebSocket-Protocol is always binary. I have an idea to not use Emscripten and sockets and instead immediately use JavaScript to create the websocket.

The thing I do not understand still is why? I’m thinking that with the type set to binary you would be able to pass any kind of data. Strings are after all bytes right?

3 Likes

I thought so too, but it’s not. Socket breaks

It’s cool idea!
I worked with sockets on corona sdk in html including. It was done on pure JS

Is there a chance for me to play around and try to connect against a server where there’s a crash when sending and receiving data?

1 Like

Made for the test. Send any text and it returns in a second

wss://lost.webday.ru/britzl_test99

1 Like