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

Godot Version

v4.2.2.stable.arch_linux

Question

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 = ENetMultiplayerPeer.new()
@export var playerScene: PackedScene
var uiInstance

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

func _on_option_chosen(option, ip, port):
	match option:
		"host":
			peer.create_server(port)
			multiplayer.multiplayer_peer = peer
			multiplayer.peer_connected.connect(_add_player)
			_add_player()
		"join":
			peer.create_client(ip, port)
			multiplayer.multiplayer_peer = peer

func _add_player(id = 1):
	var player = playerScene.instantiate()
	player.name = 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

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.