Page 1 of 1

UDP Sockets not working on Android platform

Posted: Sat Feb 15, 2020 8:23 am
by paserra
Hi,
I'm trying to work with UDP sockets on Android.
The following code works very well in the Windows version.
Do you have some suggestions for porting the code to Android?
Thank you,
Pier Andrea.

Code: Select all

local socket = require "socket"
local address, port = "localhost", 12345
local datagram = ""
local myip = socket.dns.toip(socket.dns.gethostname())

function love.load()
	udp = socket.udp()
	udp:settimeout(0)
	udp:setsockname(myip, 12345)
	love.graphics.setFont(love.graphics.newFont(24))
	love.graphics.setBackgroundColor(1, 1, 1)
	love.graphics.setColor(0, 0, 1)
end
	
function love.update()
  local data, msg = udp:receive()
		if data then
        datagram = data
		end
end

function love.draw()
		love.graphics.print(datagram, 10, 10)
end

function love.quit()
  udp:close()
end

Re: UDP Sockets not working on Android platform

Posted: Sat Feb 15, 2020 10:51 am
by pgimeno
Binding the socket to 127.0.0.1 should not allow external connections, and it doesn't in any other platform except Windows. Use 0.0.0.0 as IP instead.

That's one problem. Not sure if there are more.

Re: UDP Sockets not working on Android platform

Posted: Sun Feb 16, 2020 9:30 pm
by paserra
Thank you pgimeno, the address 0.0.0.0 works on Android!
The datagrams are received normally!