Godot Version
Godot 4.3 Stable official on Fedora Linux
Question
When I try and create a server, either it doesn't correctly bind to IP, or the client fails to connect, but both are giving me OK responses.
So I have a basic 3D game in Godot, and I was trying to add multiplayer. However, something is going wrong when I try and run the multiplayer. This is on top of a 3d game, but the first script uses command line arguments to determine which one of these scripts to load, and they load successfully.
Multiplayer script
extends Node
var server_peer: ENetMultiplayerPeer
func _ready() -> void:
server_peer = ENetMultiplayerPeer.new()
var result = server_peer.create_server(1245, 10)
if result == OK:
print("Server started successfully on port 12345")
# Correct way to assign the network_peer in Godot 4
multiplayer.multiplayer_peer = server_peer
get_tree().set_multiplayer(multiplayer)
# Connect the signals to handle peer connections
server_peer.connect("peer_connected", Callable(self, "_on_peer_connected"))
server_peer.connect("peer_disconnected", Callable(self, "_on_peer_disconnected"))
else:
print("Failed to start server. Error code:", result)
func _on_peer_connected(peer_id: int) -> void:
print("Peer connected with ID:", peer_id)
func _on_peer_disconnected(peer_id: int) -> void:
print("Peer disconnected with ID:", peer_id)
func _process(delta: float) -> void:
if server_peer:
server_peer.poll() # Make sure to poll the server for events
Client script:
extends Node
var server_peer: ENetMultiplayerPeer
func _ready() -> void:
server_peer = ENetMultiplayerPeer.new()
var result = server_peer.create_server(1245, 10)
if result == OK:
print("Server started successfully on port 12345")
# Correct way to assign the network_peer in Godot 4
multiplayer.multiplayer_peer = server_peer
get_tree().set_multiplayer(multiplayer)
# Connect the signals to handle peer connections
server_peer.connect("peer_connected", Callable(self, "_on_peer_connected"))
server_peer.connect("peer_disconnected", Callable(self, "_on_peer_disconnected"))
else:
print("Failed to start server. Error code:", result)
func _on_peer_connected(peer_id: int) -> void:
print("Peer connected with ID:", peer_id)
func _on_peer_disconnected(peer_id: int) -> void:
print("Peer disconnected with ID:", peer_id)
func _process(delta: float) -> void:
if server_peer:
server_peer.poll() # Make sure to poll the server for events
Output:
Server started successfully on port 12345
-90
0
90
Connected to server
Since both of these run at the same time when I click the run button, I have tried delaying the client connecting to the server, but that proves fruitless.
I have also tried netstating it, and the output shows that something exists, and dissappears when the server stops, but for some reason the client can’t connect? I have also tried changing the port, and I disabled Fedora’s protection, sudo setenforce 0
, and let it through the firewall, sudo firewall-cmd --zone=public --add-port=1245/tcp --permanent
, and yes, I reloaded the firewall afterwards.
NetStat output:
udp6 0 0 :::1245 :::*
Thank you!