UDP Sockets not working on Android platform

Discuss any ports of LÖVE to different platforms.
Post Reply
paserra
Prole
Posts: 6
Joined: Sun Aug 17, 2014 2:17 am

UDP Sockets not working on Android platform

Post by paserra » Sat Feb 15, 2020 8:23 am

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

User avatar
pgimeno
Party member
Posts: 2031
Joined: Sun Oct 18, 2015 2:58 pm

Re: UDP Sockets not working on Android platform

Post by pgimeno » Sat Feb 15, 2020 10:51 am

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.

paserra
Prole
Posts: 6
Joined: Sun Aug 17, 2014 2:17 am

Re: UDP Sockets not working on Android platform

Post by paserra » Sun Feb 16, 2020 9:30 pm

Thank you pgimeno, the address 0.0.0.0 works on Android!
The datagrams are received normally!

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests