Cannot create an ENet host after allowing port to be specified by user

Godot Version



Hey there everyone, just followed this simple multiplayer tutorial and it was working perfectly until I added some UI to let the user specify a port to host on. Before it was set statically in the code. Now, the server doesn’t start anymore. What’s the matter here, and how can I resolve this?
The GDScript code for my main scene looks like this:

extends Node2D

@onready var peer =
@export var playerScene: PackedScene
var uiInstance

func _ready():
	var uiScene = preload("res://mainMenu.tscn")
	uiInstance = uiScene.instantiate()
	uiInstance.connect("optionChosen", _on_option_chosen)

func _on_option_chosen(option, ip, port):
	match option:
			multiplayer.multiplayer_peer = peer
			peer.create_client(ip, port)
			multiplayer.multiplayer_peer = peer

func _add_player(id = 1):
	var player = playerScene.instantiate() = str(id)
	call_deferred("add_child", player)

and the code for my UI scene looks like this:

extends Control

signal optionChosen(option, ip, port)

func _on_host_pressed():
	var port = int($VBoxContainer/fields/port.text)
	emit_signal("optionChosen", "host", "", port)
	self.visible = false

func _on_join_pressed():
	var ip = $VBoxContainer/fields/ip.text
	var port = int($VBoxContainer/fields/port.text)
	emit_signal("optionChosen", "join", ip, port)
	self.visible = false

i’m pretty new to all this, and i’d really appreciate any help you can give me!

Have you checked that the port is a valid port with “print” for example? Ports below 1024 are priviliged ports and shouldnt be used and the highest port is 65536. Check if your port is inside these boundaries

1 Like

oh man. dude, you’re a lifesaver! i had no idea about port privelage. the tutorial guy used port 135 :sob:

1 Like