Godot Version
3.3.3
Question
I'm trying to receive packets from a udp server created with python and its socket library, but I can't receive the packets. If I use the PacketPeerUDP wait() function, my window crashes. I already checked with Wireshark and the server if the packet returns. Could someone give me some guidance with code? Thanks in advance.
extends Node
var udp_socket := PacketPeerUDP.new()
func _ready():
udp_socket.listen(10000)
print("Cliente UDP listo")
send_data("¡Hola, servidor!")
func send_data(message):
var ip = "127.0.0.1"
var port = 10000
var packet = message.to_utf8() # Convertir el mensaje a bytes UTF-8
udp_socket.connect_to_host(ip, port)
udp_socket.put_packet(packet)
print("Datos enviados al servidor")
"""
func _notification(what):
if what == NOTIFICATION_READY:
while udp_socket.wait() == OK:
var packet = udp_socket.get_packet()
var data = packet.get_string_from_utf8()
print("Datos recibidos del servidor: ", data)
"""
func _process(delta):
var result = udp_socket.wait()
if result == OK:
var packet = udp_socket.get_packet()
var data = packet.get_string_from_utf8()
print("Datos recibidos del servidor: ", data)