Couldn't create an ENet host. Parameter "host" is null

Godot Version

v4.3-dev5_mono_linux_x86_64

Question

I am trying to follow along with the Snopek Rollback Netcode tutorial series. The videos are excellent- unfortunately the tutorials have not been updated to Godot 4 and probably never will be. (The add-on itself has been.) So I’m going through and fixing the errors one at a time as they show up, looking up the new Godot 4 way to do each thing that doesn’t work as written. I am only halfway through the second video and I’m already stuck.

The server button gives this error when clicked:

main.gd:17 @ _on_server_button_pressed(): Couldn't create an ENet host.

That’s not very helpful, but if I expand it, the next message on the error stack is:

<C++ Error> Parameter "host" is null.

What? ENetMultiplayerPeer.create_server does not take a host parameter. create_client does. I figured the C++ module must be getting it from somewhere else and it needs to be set before calling create_server.

So I added the line

peer.set_bind_ip( host_field.text )

Which as far as I could tell from the docs, is how you do that. That should have told it to listen on 127.0.0.1- what it says in the GUI HostField -when I create a server. Right? Nope. Same error.

Well, that’s it. I am out of ideas.

extends Node2D

@onready var connection_panel = $CanvasLayer/ConnectionPanel
@onready var host_field = $CanvasLayer/ConnectionPanel/GridContainer/HostField
@onready var port_field = $CanvasLayer/ConnectionPanel/GridContainer/PortField
@onready var message_label = $CanvasLayer/MessageLabel

func _ready() -> void:
	multiplayer.peer_connected.connect(_on_network_peer_connected)
	multiplayer.peer_disconnected.connect(_on_network_peer_disconnected)
	multiplayer.server_disconnected.connect( _on_server_disconnected)

func _on_server_button_pressed() -> void:
	var peer = ENetMultiplayerPeer.new()
	peer.set_bind_ip( host_field.text )
	peer.create_server( int(port_field.text), 1 )
	multiplayer.set_multiplayer_peer(peer)
	connection_panel.visible = false
	message_label.text = "Listening..."

func _on_client_button_pressed() -> void:
	var peer = ENetMultiplayerPeer.new()
	peer.create_client( host_field.text, int(port_field.text) )
	multiplayer.set_multiplayer_peer(peer)
	connection_panel.visible = false
	message_label.text = "Connecting..."
	
func _on_network_peer_connected(peer_id: int):
	message_label.text = "Connected!"

func _on_network_peer_disconnected(peer_id: int):
	message_label.text = "Disconnected."
	
func _on_server_disconnected(peer_id: int):
	_on_network_peer_disconnected(1)

peer.create_server just takes a port number (and a lot of optional arguments), maybe that is the issue?

Try setting multiplayer peer via multiplayer.multiplayer_peer = peer

Thanks, but that didn’t fix it. Seems like multiplayer.multiplayer_peer = peer and multiplayer.set_peer( peer ) are the same thing.

Either way, these print commands give the same effect:

print( multiplayer.has_multiplayer_peer())

true

print (multiplayer.get_multiplayer_peer())

<OfflineMultiplayerPeer#-9223372012712360724>

but peer.create_server() still fails.

1 Like

This is what my server initializing script looks like for reference, not sure what’s all different aside from how it’s set.

	var peer := ENetMultiplayerPeer.new()

	var create_err := peer.create_server(port)
	if create_err == OK:
		multiplayer.multiplayer_peer = peer
		get_tree().change_scene_to_file("res://System/world.tscn")
1 Like

Ok, for a sanity check I created a new empty project and added a single control node with a single script on it:

extends Control

func _ready() -> void:
	var peer = ENetMultiplayerPeer.new()
	peer.create_server(9999, 1)
	multiplayer.multiplayer_peer = peer
	print( multiplayer.is_server() )

true

Works fine, no erros. So I can host an ENet server. It’s got to be the rollback netcode plugin-( Which works with 4.0, but not 4.3?) that is breaking the ENet multiplayer somehow, so I need to go back and try to fix the errors in that.

1 Like

OK, I fixed it! Just following a random hunch, I did this:

extends Node2D

@onready var connection_panel = $CanvasLayer/ConnectionPanel
@onready var host_field = $CanvasLayer/ConnectionPanel/GridContainer/HostField
@onready var port_field = $CanvasLayer/ConnectionPanel/GridContainer/PortField
@onready var message_label = $CanvasLayer/MessageLabel

@onready var peer = ENetMultiplayerPeer.new()               <--------

Instead of creating that peer variable later in the button handlers.

And now the buttons work, it actually connects, and there are no errors.
I have no idea why, but I don’t really care- now I can continue with the tutorials.

The rollback netcode addon still has errors but they are mostly with the Nakama adapter and I’m not going to mess around with that anytime soon.

1 Like