Godot Version
4.3.stable
Question
I’ve been working on a project, and seemingly one client cannot receive information, while others can. I’m thinking this may be a silly error of mine with how I choose to output during debugging, but I can’t see it. All clients run the same code, I think. Kind of a newbie with all this.
func _process(delta):
if my_connection != null and my_connection.get_status() == 2 and my_connection.get_available_bytes() > 0:
my_connection.get_string()
if server != null and server.is_connection_available() and server.is_listening():
new_connection(server.take_connection())
if process_counter > 60 and my_connection != null:
my_connection.put_string("Hello")
for i:StreamPeerTCP in connected_peers:
i.put_string("I'm a connected peer")
process_counter = 0
if connected_peers != null:
for i in connected_peers.duplicate():
i.put_string("Special")
if i != null and i.get_available_bytes() > 0:
print(i.get_string())
else:
pass
process_counter += 1
# Code to execute as the server when receiving a new attempt from a client to connect
func new_connection(peer:StreamPeerTCP):
while peer.get_status() != 2 and peer.get_status() != 3:
peer.poll()
connected_peers.append(peer)
print(peer, " connected at ", peer.get_connected_host(), " with code ", peer.get_status())
# Code to execute when attempting to host a server
func _on_menu_host_server(port:int, username:String, passcode:String):
server = TCPServer.new()
print("Server startup ended with code ", server.listen(port, "*"))
if server.is_listening():
print("Server listening on port ", port)
my_connection = StreamPeerTCP.new()
my_connection.connect_to_host('localhost', port)
while my_connection.get_status() != 2 and my_connection.get_status() != 3:
my_connection.poll()
print(my_connection.get_status())
my_connection.set_no_delay(true)
# Set global username
username = username
#Code to execute when attempting to connect with a server as a client
func _on_menu_join_server(address:String, port:int, username:String, passcode:String):
my_connection = StreamPeerTCP.new()
my_connection.connect_to_host(address, port)
while my_connection.get_status() != 2 and my_connection.get_status() != 3:
my_connection.poll()
print(my_connection.get_status())
my_connection.set_no_delay(true)
# Set global username
username = username