Page 1 of 1

Networking between devices on the same wifi connection

Posted: Thu Apr 11, 2019 7:26 pm
by pauls313
Using LuaSocket Tutorial:Networking_with_UDP, how can I send packets from, say, my phone to my laptop? I've tried using 'localhost', ''127.0.0.1", "192.168.1.0" as addresses but none of these seem to work.

Re: Networking between devices on the same wifi connection

Posted: Thu Apr 11, 2019 8:43 pm
by keharriso
You either need to make a note of your phone and laptop's IP addresses or use the broadcast address "255.255.255.255". "localhost" and "127.0.0.1" both refer to the local machine (your phone in this example).

Re: Networking between devices on the same wifi connection

Posted: Thu Apr 11, 2019 8:59 pm
by pauls313
keharriso wrote: Thu Apr 11, 2019 8:43 pm You either need to make a note of your phone and laptop's IP addresses or use the broadcast address "255.255.255.255". "localhost" and "127.0.0.1" both refer to the local machine (your phone in this example).
Neither of these work. I've opened the 8090 port on my router but I still can't receive messages on both ends, both using their respective IPs and using 255.255.255.255

Could it have something to do with my router?

Re: Networking between devices on the same wifi connection

Posted: Thu Apr 11, 2019 9:29 pm
by grump
pauls313 wrote: Thu Apr 11, 2019 8:59 pm Could it have something to do with my router?
Assuming that you're talking about an actual router, and not some kind of local firewall - probably not. The task of a router is to connect different networks. "Opening a port" on the router exposes your local network to the Internet for connections on that port, but it doesn't change anything about how local connections work, because a local network doesn't require routing by definition.

Re: Networking between devices on the same wifi connection

Posted: Thu Apr 11, 2019 11:06 pm
by keharriso
How about you upload a .love of the most basic case you can make that doesn't work. There might be a problem in the way you're doing things that we have no way of knowing about.

Re: Networking between devices on the same wifi connection

Posted: Fri Apr 12, 2019 2:20 am
by pauls313
Server:

Code: Select all

local socket = require "socket"
local udp = socket.udp()
udp:settimeout(0)
udp:setsockname('*', 12345)
local data, ip, port

function love.update(dt)
  
  data, ip, port = udp:receivefrom()
  
end

function love.draw()
  if data then
    love.graphics.print(data, 300, 300)
  end
end
Client:

Code: Select all

local socket = require "socket"
local address, port = "192.168.16.102", 12345
udp = socket.udp()
udp:settimeout(0)
udp:setpeername(address, port)

function love.update(dt)
  udp:send("Hello!")
end

Re: Networking between devices on the same wifi connection

Posted: Fri Apr 12, 2019 1:44 pm
by keharriso
Try changing your server code to this:

Code: Select all

local socket = require "socket"
local udp = socket.udp()
udp:settimeout(0)
udp:setsockname('0.0.0.0', 12345)
local data, ip, port

function love.update(dt)
  local msg
  msg, ip, port = udp:receivefrom()
  if msg then
	data = msg
  end
end

function love.draw()
  if data then
    love.graphics.print(data, 300, 300)
  end
end
There are two changes:
1. The "*" address appears to be bugged on Windows, so use "0.0.0.0" instead.
2. Save the last received message to be displayed instead of overwriting it every update.

Re: Networking between devices on the same wifi connection

Posted: Sat Apr 13, 2019 6:51 pm
by pauls313
keharriso wrote: Fri Apr 12, 2019 1:44 pm Try changing your server code to this:

Code: Select all

local socket = require "socket"
local udp = socket.udp()
udp:settimeout(0)
udp:setsockname('0.0.0.0', 12345)
local data, ip, port

function love.update(dt)
  local msg
  msg, ip, port = udp:receivefrom()
  if msg then
	data = msg
  end
end

function love.draw()
  if data then
    love.graphics.print(data, 300, 300)
  end
end
There are two changes:
1. The "*" address appears to be bugged on Windows, so use "0.0.0.0" instead.
2. Save the last received message to be displayed instead of overwriting it every update.
Thanks! The "*" seemed to be the problem.