Run Server on Client PC

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

I am trying to make a Mini-Game Library with some multiplayer games. I would like to do it so everyone can just create a lobby which runs on their PC and other people can connect to it.

I am really unsure on how to approach it because I’m not experienced with Godots High-Level Networking and everything else network related I did was in Node.js with a public server always running and handeling all the connections.

I would just like some tips on how to start setting something like this up.

Thanks in advance ^^

I solved it
It seems that we have to look closely at the IP of the PC directly in the ethernet state, there is the real IP while Godot, due to my bad configuration, throws me another IP so that it is already there
In addition to that we must give permissions to the app before exporting with godot
Internet and Access network satate
With that the connection between pc and android is successful greetings!

lurgx | 2022-06-04 09:08

:bust_in_silhouette: Reply From: archeron

A “server” is just a program listening for network connections while it is running. It really makes no difference whether the server sits on a remote machine which is running 24/7 or at your local machine (well, the important differences are that a local server will usually only be available to your local network – if you don’t punch a hole into your internet router’s firewall and set up port forwarding, that is – will use your machine’s local IP address, and will of course only be available if it is running).

In respect to Godot, again, a server is just a Godot Game that does the job of a server. Since pure servers usually don’t need to display anything on screen, Godot comes in a special “headless server” variant which doesn’t pack all the display stuff, but you don’t need to use that in order to develop server software.

You can just write two Godot Games - one that connects to the server “game” as a client, and one that provides the lobby services by listening for connections and sending back lobby data.

How you do this really can’t be explained in the Q/A format. There really is no way around getting to know Godots networking capabilities. If I were you, I’d start by writing a client and a simple echo server that just parrots back whatever the client sends it, and then develop it from there.

You can actually write both the client and the server in the same program, and design a way for the program to switch from client to server, maybe by pressing a button on the user interface. Thenjust run two instances of the program, and make one be the server. That makes for quick development, even though later on you’ll probably want to split the server off from your game client.

Ok this is basically what I expected…
I guess if I would want to run a server on a PC of the user the user would have to open the ports manually. Or can I do this in code somehow?

If this isn’t possible in code I would propably just set up a public server running on heroku which lets people make lobbies.

I just thought doing it on local machines would drastically lower the traffic on every server.

vequa | 2021-03-26 14:32

It’s pretty much impossible to automatically open firwall ports and set up reverse port forwarding consistently for all your users. There are router configuration protocols designed to make this possible, but not every router has the protocols enabled - often the owners need to enable these protocols manually since they’re a bit of a security risk. The world is just too diverse for this to work reliably.

OTOH, people who are seriously into multiplayer gaming often know how to configure their routers, since they’re often playing other games that need direct connections from the internet to their machines.

So… it just depends how foolproof you want to make this. But don’t forget: Even if you use a public server to set up lobbies, if you expect players to connect directly to other player’s machines after making contact in the lobby, you’ll still have to get around the firewall/port forwarding issue.

archeron | 2021-03-26 14:38

Ok I guess for this little project I will stick to one server handeling everything.
I have two last questions…

  • I would like this Game to run on Windows and HTML5. Will everything network related still work just by exporting to HTML5?
  • I am thinking of writing my Server in Node.js because I have a bit of experience there. Is this possible without any mature inconvenience?

Thanks for the great help ^^

vequa | 2021-03-26 14:45

Re HTML5, I’m not sure, as I haven’t tried it so far. Re Node.js, sure, you’ll just have to handle your protocols on a lower level - Godot provides you with high level RPC etc which you’ll forgo if you use Node.js.

archeron | 2021-03-26 16:36