Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | kakcalu13 |
I’m trying to get any data from a different UDP outside of Godot to UDP inside godot.
For some reason, it didn’t work as I wanted it to.
Here is the code inside godot:
var done = false
var data
var socket = PacketPeerUDP.new()
#var udp := PacketPeerUDP.new()
#socket.set_dest_address("127.0.0.1",20001)
data = socket.listen(20001, "127.0.0.1")
data = socket.get_packet().get_string_from_utf8()
print("Data: ", data)
print("Exiting application")
Keep in mind, this is in loop. What did I miss to get the data?
Thank you greatly for your time
Can you detail “it didn’t work as I wanted it to”? Are you getting any data at all? If so, what does it look like?
Calinou | 2021-11-17 00:19
Hey, thank you for your reply! I got it figured. The code is:
var socket = PacketPeerUDP.new()
func _ready():
if (socket.listen(20001, "127.0.0.1") != OK):
print("boom!"
else:
print("yay!")
func _process(delta):
while socket.get_available_packet_count() > 0:
var data = socket.get_packet().get_string_from_utf8()
print(data)
kakcalu13 | 2021-11-17 17:44