How to transfer data between PCs in Godot4

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

Hello! Is it possible to use any of these methods to create a desktop multiplayer: ENet, QUIC. But just NetworkMultiplayerPeer does not work for me. I want to write the synchronization myself, I just need to transfer the dictionary between PCs (my game is only for Windows). I asked about it in ChatGPT and he only answered about it for Godot 3.0, not Godot 4.0(I could go back to Godot3, but I’m more comfortable with Godot4+there are some great new features) My game is a copy of Minecraft and I want to give the player the ability to play over LAN just like in the original Minecraft.

:bust_in_silhouette: Reply From: stormreaver

I use PacketPeerUDP directly for my multiplayer implementation. I find it easier to use, in most cases, than the built-in multiplayer.

Thanks for the answer! If you use this a lot, could you give an example of using it?(simple PC to PC data transfer)

roma | 2023-04-09 11:12

My PacketPeerUDP usage is not easily separable from my client/server code. It would take more time than I have available to construct a useful, self-contained example.

However, the official documentation covers making a UDP client and server, which is what I used as a starting reference. Godot 4 changed a little in function naming over Godot 3, but the core is the same. If your dictionary is smaller than a single MTU (about 1500 bytes), you can transfer the whole thing in a single put_packet() call.

stormreaver | 2023-04-09 11:59

Sorry, I was asking if you could provide the server and client code to simply send string data to the server by the client and send the data to the client by the server multiple times per second? I just don’t know anything about the network, but I want to read the code that will work like this (in Godot 4.0): there is a string “Hello” that needs to be sent to the server. Then the server accepts it, and writes to the console from whom it is and this tape. After that, the server sends something to the client, and it has to accept it and output it to the console. (Sorry, this is printed by Google Translate)

roma | 2023-04-09 14:26