Is ther a toturial on how to host online game free...?

Godot Version

4.7 .2

Question

Is ther any tutorial on how to make a working online game free to host? (peer to peer over the internet? maybe?)
My problem is I can’t pay for a server :frowning: but ther are free servers (I think) but all godot tutorials bee like: setup multiplayer spawner and syncer node and.. bye! hosting should be super easy… (video ends)

IT IS NOT!

thank you for reading.

ps: I just want to test stuff with friends, I dont need a scalable server architecture or so…

It sounds like you need a 101 on networking in general. What networking strategy you use may influence your game.

Servers are not special, they are normal computers connected to the internet like any other. Some games use a central server that does not play the game, only allowing players to connect and relay data back to them; this is typically MMOs. Shooters may also use central servers and a separate server for “matchmaking” which tells the clients which game server to connect to so games are fair. Many and most other games will use a self-hosted approach where one player must host their own server, typically this only takes a check box from the game, but may require port forwarding in the user’s router settings. Self-hosted is “free” to you as the developer since you are pushing the server hardware needs onto your players.

Most tutorials are about how to create a “free” self-hosting multiplayer game, where the “host” is also a player. Sometimes this is called “peer-to-peer”, but it’s more a strategy than a special type of server. There is still a designated host and the client(s) talk to the host while the host broadcasts to the client(s), the same as any other server/client setup.

If you have a multiplayer game already built, you may need only to give your friend your own IP address, which must be found online, and let them connect while your game is in a hosting state. Again your router may be blocking this traffic by default, that’s what port forwarding is for, and you may be able to get around it with UPnP

Here’s the setup I used for everything in my game. I have logins, accounts, peer-to-peer PvP or co-op, etc.

Thank you soooo much @gertkeno and @ComicallyUnfunny! <3
I was kinda stuck on multiplayer and could not find information when searching for: “how to host my muliplayer games for free” or “peer to peer free multiplayer” etz.

Could this already run on my local network (LAN)?
I followed this tutorial here to 65:00, : https://www.youtube.com/watch?v=tWLZNCJISYU&list=PLOtt3_R1rR9VMVlRIVVIBeC7Jg5mankyY&index=1
​do I just build the project on my PC on my local network, and it works with my friends pc also connected to my local network?

And if I do this :backhand_index_pointing_up:t3: it works trough the internet to my theoretical friend in faar faar away for FREEE :grin: ?

Probably, skimming through it looks like pretty standard multiplayer, this falls under that “Most tutorials” I stated targeting your free self-hosting use case. Local networks also may use a different local ip-address, typically starting with 192.168.xx.xx

Yes, I host my servers from home, a little computer sits humming away in my office under the printer.

As a bonus here’s my UPnP manager script, UPnP helps to make port forwarding automatic; if your router supports it.

I add this as an Autoload/Global, typically controlled by a CheckBox node. Normally Godot’s UPnP is blocking, so this script handles it on another thread. But if you are OK with blocking, and not handling errors, then this script isn’t needed much and likely over complicates compared to following the docs.

extends Node

@onready var app_name: String = ProjectSettings.get_setting("application/config/name", "Godot UPNP")
var _open_udp_ports: Array[int] = []

var _upnp: UPNP
var _upnp_thread: Thread = null
signal upnp_finished(error_msg: String)

func open_upnp_port(port: int) -> void:
	_check_thread()

	_upnp_thread = Thread.new()
	_upnp_thread.start(_setup_upnp.bind(port), Thread.PRIORITY_LOW)
	set_process(true)


func close_upnp_port(port: int) -> void:
	_check_thread()

	_upnp_thread = Thread.new()
	_upnp_thread.start(_teardown_upnp.bind(port), Thread.PRIORITY_LOW)
	set_process(true)


func _setup_upnp(port: int) -> String:
	if _upnp == null:
		_upnp = UPNP.new()

	if _upnp.get_device_count() == 0:
		# The slowest function is discovery
		var discover_error := _upnp.discover()
		if discover_error != UPNP.UPNP_RESULT_SUCCESS:
			push_warning("Failed to discover UPnP: ", discover_error)
			return "Discovery failed"

	if port in _open_udp_ports:
		return "" # already open

	var gateway := _upnp.get_gateway()
	if gateway and gateway.is_valid_gateway():
		var mapping_error := _upnp.add_port_mapping(port, port, app_name)
		if mapping_error != UPNP.UPNP_RESULT_SUCCESS:
			push_warning("Failed to map UPnP port: ", mapping_error)
			return "Mapping failed"
		_open_udp_ports.append(port)
		return "" # successful open
	else:
		return "No gateway"


func _teardown_upnp(port: int) -> String:
	if not port in _open_udp_ports:
		return "Port not open"

	var gateway := _upnp.get_gateway()
	if gateway and gateway.is_valid_gateway():
		var mapping_error := _upnp.delete_port_mapping(port)
		if mapping_error != UPNP.UPNP_RESULT_SUCCESS:
			return "Failed to remove port"
		_open_udp_ports.erase(port)
		return "" # successful close
	else:
		return "No gateway to remove from"


func _exit_tree() -> void:
	_check_thread()
	for open_port in _open_udp_ports:
		_upnp.delete_port_mapping(open_port)


func _check_thread() -> void:
	if _upnp_thread and _upnp_thread.is_started():
		_upnp_thread.wait_to_finish()


func _ready() -> void:
	set_process(false)


func _process(_delta: float) -> void:
	if _upnp_thread and _upnp_thread.is_started():
		if _upnp_thread.is_alive():
			return

		var err_msg: String = _upnp_thread.wait_to_finish()
		upnp_finished.emit(err_msg)

	set_process(false)

Thank you! :blush: