Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket module #14888

Merged
merged 4 commits into from
Feb 7, 2018
Merged

Websocket module #14888

merged 4 commits into from
Feb 7, 2018

Conversation

Faless
Copy link
Collaborator

@Faless Faless commented Dec 21, 2017

Webassembly support is client-only for obvious reasons.
Other platforms support both client and server using libwebsockets.

Libwebsockets is released under LGPLv2.1 + static linking exception (and others, like not having to distribute the license itself, see the LICENSE.txt for details).

The module itself can easily work with other libraries, since it's done with custom implementations of generic WebSocketClient WebSocketServer and WebSocketPeer classes to allow for webassembly native implementation.

The module also supports the Multiplayer API, but beware that websocket uses TCP, and it's always reliable. This means that latency will grow indefinitely if you send too many RPCs.
This is fine for most non-realtime games, e.g. turn based, browser games, etc. and it's a first step toward having both web and server implementations done with godot, same scene, seamlessly.

The next step, when time allows, would clearly be WebRTC.

EDIT:
Closes #5806.
Brings #14627 to a better state.
Partly unrelated but #9624 should be closed as HTTPClient works in 3.0 for webassembly export.

@Faless
Copy link
Collaborator Author

Faless commented Dec 21, 2017

I can't explain the failed build on X11 platform. It's my main platform, and it builds fine here with both builtin and distro's openssl

@Faless
Copy link
Collaborator Author

Faless commented Dec 21, 2017

In any case SSL with lws is not yet implemented properly, so I might just disable it for now.

@akien-mga
Copy link
Member

akien-mga commented Dec 21, 2017

Also builds fine for me on X11 (Mageia 6 x86_64). Might be related to the OpenSSL version on Travis/Ubuntu 14.04?

@Faless
Copy link
Collaborator Author

Faless commented Dec 21, 2017

Might be related to the OpenSSL version on Travis/Ubuntu 14.04?

You are totally right, apparently LWS requires OpenSSL >= 1.0.2 and ubuntu 14.04 seems to still have OpenSSL 1.0.1f . I for once agree with you @akien-mga that ubuntu packages sucks.
See warmcat/libwebsockets#666 (comment) and warmcat/libwebsockets@e7bf0aa

I see that function is protected by an ifdef block, I can try to disable SSL hostname verification and maybe try to implement it in a compatible way later.

@Faless
Copy link
Collaborator Author

Faless commented Dec 21, 2017

Okay, it builds now, I'm pretty positive the client no longer does SSL hostname verification though.

We could fix it in the lws callback. I'm not sure if I'll have the time before January, but I'll try.

@akien-mga
Copy link
Member

Otherwise we can just build on travis against the builtin openssl which is 1.0.2 (might increase build time a bit, but with the cache it shouldn't be too bad).

@Faless
Copy link
Collaborator Author

Faless commented Dec 21, 2017

Otherwise we can just build on travis against the builtin openssl which is 1.0.2 (might increase build time a bit, but with the cache it shouldn't be too bad).

I guess official export templates for linux are shipping with builtin openssl.
In that case I'd say let's just bump openssl min version requirements :)

@akien-mga
Copy link
Member

I guess official export templates for linux are shipping with builtin openssl.

Yep: https://github.com/GodotBuilder/godot-builds/blob/master/.travis.yml#L26

In that case I'd say let's just bump openssl min version requirements :)

Go ahead. You can remove your last commit then and tweak .travis.yml so that it builds against the builtin openssl.

.travis.yml Outdated
@@ -8,6 +8,7 @@ env:
global:
- SCONS_CACHE=$HOME/.scons_cache
- SCONS_CACHE_LIMIT=1024
- OPTIONS="verbose=yes progress=no openmp=no"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akien-mga you said tweak, I tweaked 😉

@akien-mga akien-mga added this to the 3.0 milestone Jan 4, 2018
@akien-mga
Copy link
Member

Thanks a lot for your contribution!
We are now entering a strict release freeze for Godot 3.0 and will only consider major bug fixes. We won't merge new features and enhancements anymore until 3.0 is released.

Moving this PR to the 3.1 milestone, to be reviewed once the release freeze is lifted. It could eventually be cherry-picked for a future 3.0.1 maintenance release if it doesn't change the user-facing APIs and doesn't compromise the engine's stability.

@akien-mga
Copy link
Member

It seems to fail building on X11 and Windows.

@hpvb
Copy link
Member

hpvb commented Feb 1, 2018

also the mbed_tls stuff should probably be removed. It seems like a bad idea to have two separate ssl implementations in the tree.

@reduz
Copy link
Member

reduz commented Feb 1, 2018 via email

@hpvb
Copy link
Member

hpvb commented Feb 1, 2018

@reduz I guess that'll depend on whether or not curl can work with mbedtls.

@Faless
Copy link
Collaborator Author

Faless commented Feb 1, 2018

It seems to fail building on X11 and Windows.

Yes, my bad, I forgot to update it to comply the last minute change to the NetworkedMultiplayerPeer API (peer.transfer_mode property).
Should compile again now (does for me on X11)

@akien-mga
Copy link
Member

I'd also support dropping openssl in favour of a more lightweight alternative.

At least in raw number of files, mbedtls seems quite smaller than openssl: https://github.com/ARMmbed/mbedtls/tree/development/library https://github.com/ARMmbed/mbedtls/tree/development/include/mbedtls

@Faless
Copy link
Collaborator Author

Faless commented Feb 1, 2018

also the mbed_tls stuff should probably be removed. It seems like a bad idea to have two separate ssl implementations in the tree.

@hpvb the mbed_tls code does not get included by modules/websocket/SCsub so it does not (should not?!) be compiled at all (it doesn't in my tests).

It's left there because I prefer to not fiddle around with library files and allow to simply copy/paste them from the library source when a new version is released. It's true that it makes the Godot source tree slightly bigger but the resulting binary is not affected at all

@hpvb
Copy link
Member

hpvb commented Feb 1, 2018

@Faless we've previously always deleted files that we don't build from thirdparty/ (look at what was done to thekla_unwrap for instance).

@akien-mga
Copy link
Member

Indeed, we always copy only what we need from thirdparty sources, which is why https://github.com/godotengine/godot/blob/master/thirdparty/README.md has sections describing for all libraries what files should be extracted from the upstream tarball or repo.

@Faless
Copy link
Collaborator Author

Faless commented Feb 1, 2018

we've previously always deleted files that we don't build from thirdparty/ (look at what was done to thekla_unwrap for instance).

I see, well, I'll check what files I can remove then.

@akien-mga
Copy link
Member

Could you squash that last commit into the first one? This way we'll never have added this code to the repo ;)

@Faless
Copy link
Collaborator Author

Faless commented Feb 1, 2018

Could you squash that last commit into the first one? This way we'll never have added this code to the repo ;)

Sure, I'll wait for the tests to finish so I'm sure it compiles everywhere (did some test here, but only cross-compiling from Linux)

License is LGPLv2.1 + static linking exception, version is 2.4.1
Webassembly is client-only for obvious reasons.
Other platforms support both client and server using libwebsockets.
1.0.2 is now the minimum version of openssl to build against
@Faless
Copy link
Collaborator Author

Faless commented Feb 6, 2018

Sqaushed commits, updated to latest Emscripten API

@akien-mga akien-mga merged commit b0a7307 into godotengine:master Feb 7, 2018
@LikeLakers2
Copy link
Contributor

Apologies if I'm missing something, but I'm looking at the files under modules/websocket/, and I'm noticing several instances under the lws_*.cpp and emws_*.cpp files where there's a get_connected_port function. At a guess, this is probably a function to get the port that's being used for the connection. So assuming my guess is right, why are all of them set to return a static 1025 rather than the port variable? It just seems odd, like it was being used for debug and wasn't removed for production.

@Faless
Copy link
Collaborator Author

Faless commented Feb 9, 2018 via email

@matty
Copy link

matty commented Jun 3, 2018

Would just like to add that I have built Godot from master on Win 10 and I am using the WebSocket implementation and it's working well so far.

@Faless Faless deleted the websocket branch September 13, 2018 01:07
@endel
Copy link

endel commented Dec 21, 2018

Hi @Faless, is this WebSocket implementation tied to Godot Engine internals, or is it possible to use it in other environments as well?

I'd like to implement a Colyseus client targeting any C++ engine (Cocos2D-X, Godot, Unreal Engine), and I'm wondering if using this WebSocket implementation would suit this need.

Thanks a lot! Enjoy the holidays!

@Faless
Copy link
Collaborator Author

Faless commented Dec 21, 2018

@endel when using gd_mp_api=false (default) both WebSocketClient and WebSocketServer simply acts as a standard-conformant implementation of RFC6455, so they will be compatible to any other RFC6455-conformant software.
If you enable gd_mp_api=true (i.e. you use it for high level multiplayer API), the internal Godot protocol for peer exchange and rpc/rset relaying is used on top of the standard WebSocket protocol (so it will be compatible, but data will be always transferred as binary, and will contain additional protocol data).

@joaopedrosgs
Copy link
Contributor

there is any documentation about this?

@Faless
Copy link
Collaborator Author

Faless commented Jan 15, 2019

@joaopedrosgs well, there's the official doc for the WebSocketClient class: http://docs.godotengine.org/en/latest/classes/class_websocketclient.html#description

@vini-guerrero
Copy link

Is there any tutorial on connectin this with a simple nodejs server? ( is that possible? )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

-
9 participants