How does WebRTC work in Godot?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Deb4ik

Hi there! I’m making the online game on HTML5 platform. I need to make client-server architecture connection because my game is competitive game and peer-to-peer isn’t suitable (quite easy make cheats).

I already did client-server using by high-level API and it works fine. But when I export my project to HTML5 to test it I was surprised that high-level API doesn’t work there. Later I found out that for HTML5 platform I must use WebRTC and WebSockets directly on your own. Ok, it’s confused me but ok I went to documentation about these things. And here I absolutely did understand nothing.

I need to use UDP protocol and client-server but for WebRTC as I understood I need to use WebSockets but WebSockets works only with TCP. And as I understood WebRTC in godot implemented only for peer-to-peer.

I thought maybe I can to make one server WebRTC peer and connect other peers to it. But even unclear how to make remote connection using by WebRTC because on the documentation wrote nothing about remote connection.

All in all, it’s difficult and below I wrote main questions.

  1. Maybe does exist a way to use High-Level API on HTML5? (If does, the questions below aren’t matter)
  2. Does exist any good explanation how to use WebRTC in Godot?
  3. How to implement client-server using by WebRTC? (With using TCP/UDP)

By the way, I know that exist demo project with WebRTC. But there using peer-to-peer connection with WebSocket as signaling server. I don’t need it.

Thanks in advance!

Did you manage to read through the documentation - WebRTC — Godot Engine (stable) documentation in English? I did not see anywhere that Web Sockets are being used as the Transport when working with WebRTC. In fact:

WebSockets, though, still use a TCP connection, which is good for reliability but not for latency, so not good for real-time applications like VoIP and fast-paced games.

For this reason, since 2010, Google started working on a new technology called WebRTC

WebRTC is a much more complex set of specifications, and relies on many other technologies behind the scenes (ICE, DTLS, SDP) to provide fast, real-time, and secure communication between two peers.

I believe that the high-level API you are looking for is this: WebRTCMultiplayer

Juxxec | 2022-11-27 11:58