On the server side, you need to store the received query's IP and port in order to send the reply back to the correct address. Something like:
Code: Select all
--server load
match_name = "casual free-for-all, no cheaters plz"
--server update
local data, ip, port = udp:receivefrom()
if data == "get data" then
udp:sendTo("match named "..match_name, ip, port)
end
On the client, you want to maintain a list of confirmed matches:
Code: Select all
--client load
confirmed_matches = {}
local IPs = get_matches()
...
--client update
local data, ip = udp:recievefrom()
if strsub(data, 1, 12) == "match named " then
local match_name = strsub(data, 13)
table.insert(confirmed_matches, {ip=ip, name=match_name})
end
Now
confirmed_matches will fill up with responses from the servers as they arrive, including the match names. In this example, the data is only the reply "match named " and then the rest of the data is the name. Obviously you'll need to figure out your wire format by your actual data requirements.