UDP Recommended Practices

Use Cases

Data Buffer

There is no buffer for received data like a TcpSocket, so you would need to use your own buffer logic if you don't expect to receive complete payloads each time. This can be achieved with a global variable that concatenates UDP data to then call a function that loops while it can find valid data.

Copy
UDP Buffer Example for fixed delimiter
buffer = ""
udp.EventHandler = function(socket, packet)
  buffer = buffer .. packet.Data -- add data to the buffer
  ProcessBuffer() -- process the buffer
end 

function ProcessBuffer()
  while buffer:find('\r') do -- loop through valid data
    local data = buffer:sub(0,buffer:find('\r') - 1) -- pull data from the buffer without delimiter
    buffer = buffer:sub(buffer:find('\r') + 1) -- remove data from the buffer
    print(data) -- do something with the data
  end 
end 

Binding to ports and network interfaces

Considerations for Core redundancy

Differences in Emulation