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

Idea: Networking/Sockets #67

Open
isc30 opened this issue Jun 17, 2019 · 3 comments
Open

Idea: Networking/Sockets #67

isc30 opened this issue Jun 17, 2019 · 3 comments

Comments

@isc30
Copy link

isc30 commented Jun 17, 2019

It's really difficult to find a good/lightweight library with no dependencies that also compiles with emscripten regarding sockets.

  • SDL2_net: supported but it adds a lot of overhead (it requires -s USE_SDL=2 -s USE_SDL_NET=2) and it isn't easy to integrate (no websocket layer for the server, many bugs, many incompatibilities, etc)
  • POCO (latest version): doesn't compile well with emscripten
  • Boost.asio / Boost.Beast: too complicated to use and I'm not sure if they are even supported by emscripten (maybe they are after you make them fallback to unix sockets internally)

I know this is a crazy idea that maybe should be added as a plugin/integration to Magnum but it would open a world of possibilities

Wasm + GPU Graphics + Audio + Networking == fully fledged game framework

@mosra mosra added this to TODO in Project management via automation Jun 20, 2019
@mosra
Copy link
Owner

mosra commented Jun 20, 2019

As far as I understand, you're building a WASM-only game/engine, so then something Emscripten-specific could work too, right? This introduction from @Squareys might help: https://blog.squareys.de/emscripten-sockets/ We actually discussed introducing wrappers for these APIs directly to Corrade/Magnum but then other things took a priority.

Looking at how Emscripten wraps websockets to mimic the Unix sockets, I'm wondering if there's a way to use those APIs directly, without the extra wrapper layer (and possibly code size / runtime overhead). ... actually, there seems to be something: https://emscripten.org/docs/api_reference/emscripten.h.html#socket-event-registration (I didn't use any of these myself, though).

Hope this helps!

@isc30
Copy link
Author

isc30 commented Jun 22, 2019

Not exactly, my idea is to build a generic setup project that works well when targeting native mobile, web and desktop (client and server). This is why magnum is an excellent choice in terms of graphics and audio.

The ultimate goal would be to write a game I have in mind, but it requires a networking so I'm currently investigating what could I use. Ideally a thin abstraction layer over sockets would be enough but if it has more things (like a websocket protocol already implemented for the server) then it would be better.

I also discovered HumbleNet that looks like the best alternative for P2P games where the host could be one of the players.

I'm still thinking if making a new lib with custom optimized bindings in emscripten and part of the API using HumbleNet is a good idea.

@Squareys
Copy link
Contributor

Squareys commented Jun 22, 2019

Hi @isc30 !

I am building a WASM-centered engine based on magnum and have written a networked WASM game with Magnum before (=> WebVR Pong, though the network mode is currently disabled):

  • Emscripten sockets are WebSockets, which is a TCP based protocoll and seemsto be not well suited for real-time networked games. Like HubleNet does, you should use WebRCT instead, probably, but I have not looked into that yet.
  • I have some Corrade::Net::Socket which has a Windows and Emscripten implementation. WebSockets are not normal sockets, as mentioned, hence on server side, there is a difference between an Emscripten-based client and a Windows-based client connecting.
  • WebSockets are not Peer-to-peer. WebRTC on the other hand is, afaik.
  • Poco is nice, I use it a lot for the server side. Since they implement the WebSockets protocol also, you can use that as a central game server when going the WebSockets route (like with WebVR pong). I would not recommend using it for an Emscripten game client.

Abstractions are nice, but when it comes to sockets, trying to abstract those for emscripten seems to mainly cause a lot of confusion.

HumbeNet looks nice, using something like that is probably the way to go.

Feel free to ask more, if that doesn't answer your questions 🙂

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

No branches or pull requests

3 participants