Networking between devices on the same wifi connection
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Networking between devices on the same wifi connection
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
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).
LÖVE-Nuklear - a lightweight immediate mode GUI for LÖVE games
Re: Networking between devices on the same wifi connection
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
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
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.
LÖVE-Nuklear - a lightweight immediate mode GUI for LÖVE games
Re: Networking between devices on the same wifi connection
Server:
Client:
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
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
- Attachments
-
- client.love
- (270 Bytes) Downloaded 248 times
-
- server.love
- (304 Bytes) Downloaded 259 times
Re: Networking between devices on the same wifi connection
Try changing your server code to this:
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.
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
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.
LÖVE-Nuklear - a lightweight immediate mode GUI for LÖVE games
Re: Networking between devices on the same wifi connection
Thanks! The "*" seemed to be the problem.keharriso wrote: ↑Fri Apr 12, 2019 1:44 pm Try changing your server code to this:There are two changes: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
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.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 3 guests