Multi-player (server/client) setup
Asked Answered
P

12

0

Hi all! Very excited to post here for the first time! I've been a Unity developer since 2014 and the recent changes have made me lose all faith in them as a platform and company. So I'm turning to Godot! I've messed around with it a little bit over the last year or so, but never got very far before having to drop off.

I've been working on a multi-player game for a while now and I want to try remaking it in Godot. The game has a dedicated server structure and I want to find how to do that in Godot. From what I can find on google/YouTube there are a few tutorials ok setting up server/client projects, but they seem to be all for Godot 3. I've found a few p2p tutorials for 4, but p2p doesn't work for me. Is there a place to check out the basics of networking for Godot 4?

Just a list of what I need:

  • starting server
  • starting client
  • automatically connecting client to server
  • being able to send information between client and server, to either all players or specific players

Any help at all here would be greatly appreciated!

Penrose answered 13/9, 2023 at 18:44 Comment(0)
A
0

Hi and welcome!

I think your best bet will be official documentation: https://docs.godotengine.org/en/stable/tutorials/networking/high_level_multiplayer.html

It goes over the things you listed.

Albumen answered 13/9, 2023 at 19:43 Comment(0)
P
0

Albumen Oh Awesome! Thanks! I figured there would be some kind of documentation like this, I'll give some time and energy and go from there. Thanks!

Penrose answered 13/9, 2023 at 20:10 Comment(0)
P
0

Penrose Is there a place to check out the basics of networking for Godot 4?

If you want simple low-level raw byte (or text) communication, check out the WebSocketClient and WebSocketServer examples.

They might be slightly outdated already, but should work fine for Godot 4.X. (maybe minor adjustments are needed)
Godot 3.X had a even simpler WebSocket implementation, but it was replaced with the examples I linked for some reason.

It's pretty much as simple as creating a server, calling server.listen(port) and polling for events such as incoming data or a new client attempting to connect.
Same on the client: create it, call client.connect(url) and poll for events such as disconnect or received data.
What exactly you send and receive that way is up to you then.

Periphrastic answered 13/9, 2023 at 20:13 Comment(0)
P
0

Albumen I got to give them a quick try and it all seems to be working! Only small question now is sending data. It seems the tutorial uses RPC calls, which are great, but they seem to be based on the same program being used for both server and client. But I want them to be completely separate projects! Are there any articles that delve into this? That show how to send data to separate programs?

Penrose answered 14/9, 2023 at 0:16 Comment(0)
P
0

Periphrastic oh awesome! Thanks! I'll give them a look over. The other articles were a good start, but I think their system is slightly different than what I am looking for (or maybe just what I'm used to)

Penrose answered 14/9, 2023 at 0:16 Comment(0)
A
0

Penrose If you want a separate client and server project, make sure that the names of the nodes, and the rpc method names (and parameters), and amount of them on each node are the same.

Allhallowmas answered 14/9, 2023 at 1:9 Comment(0)
P
0

Allhallowmas Sounds pretty similar to the system I was using back in Unity, thanks for the tip!

If I want to send data, and I required to use RPC? Or are there other ways to send data?

I'm starting out super simple right now, just trying to send a string "hello world" from client to server after connecting. I can get them to connect, which is fairly simple with the documentation. Now I am trying to get a func to send a string. Still working out exactly how it needs to be written, but at the most basic level its just an RPC func right?

Penrose answered 14/9, 2023 at 13:10 Comment(0)
A
0

Penrose I think you should be able to do an rpc function which takes the string as an argument.
If you want more low-level approach, you can do TCP/UDP/WebRTC/WebSocket connections, but they require more setup.

There are also a few nodes that might be helpful: MultiplayerSpawner and MultiplayerSynchronizer

I also found this official blogpost, which shows how to use these nodes and other new features.

Albumen answered 14/9, 2023 at 14:1 Comment(0)
E
0

Changed the tags to the more appropriate ones as this is more about asking for help . 👍

Erminiaerminie answered 14/9, 2023 at 19:9 Comment(0)
A
0

You still need a backend application if you want to separate server and client.
Godot's high-level multiplayer only supports object attributes synchronization, for game logics you still need a gds backend as authority server, then use rpc to call server functions, or you could just use low level enet wrapper to communicate with server application in any language.

Armandoarmature answered 15/9, 2023 at 2:26 Comment(0)
P
0

Armandoarmature that should be OK for what I need. Is a Gds server just a gcode version? Like a headless server?

Penrose answered 25/9, 2023 at 22:23 Comment(0)
A
0

Penrose I think a gds server with GUI won't hurt either.
But for server on cloud vps etc, headless is a betterchoice.

Armandoarmature answered 27/9, 2023 at 6:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.