Code: Select all
socket.sleep(0.1)
Code: Select all
socket.timeout(0)
Code: Select all
udp:setsockname ('*', 65000)
This is the client main.lua now:
Code: Select all
local socket = require("socket")
local ipaddr = "192.168.1.71"
local udp = socket.udp()
udp:setsockname('*', 65000)
local sendit
function love.load()
end
function love.keypressed(key)
if key == 'g' then
sendit = not sendit
end
end
function love.update(dt)
if sendit then
result, err = udp:sendto("Message", ipaddr, 65000)
end
end
function love.draw()
local delta = love.timer.getAverageDelta()
-- Display the frame time in milliseconds for convenience.
-- A lower frame time means more frames per second.
love.graphics.print(string.format("Average frame time: %.3f ms", 1000 * delta), 0, 0)
fps = love.timer.getFPS( )
love.graphics.print("Current FPS: "..tostring(love.timer.getFPS( )), 0, 15)
love.graphics.print("Client: "..ipaddr, 0, 35)
if sendit then
love.graphics.print("sending",50,50)
love.graphics.print(result..err,50,80)
end
end
, I did set result and err to "0" and it printed it fine so it looks like sendto isn't working at all?attempt to concatenate global 'result' (a nil value)
Just so we all on the same page, here is server main.lua:
Code: Select all
local socket = require("socket")
function love.load()
serverThread = love.thread.newThread("listen.lua")
serverThread:start()
local err = serverThread:getError()
address = "Server Address: " .. socket.dns.toip(socket.dns.gethostname())
end
function love.keypressed(key)
if key == 's' then
elseif key == 'q' then
love.event.quit(exitstatus)
elseif key == 'r' then
love.event.quit( "restart" )
end
end
function love.update(dt)
local message = love.thread.getChannel('messages'):pop() --set to peek not pop so the first sent it shown
local ip = love.thread.getChannel('ips'):pop()
local port = love.thread.getChannel('ports'):pop()
assert( not err, error )
end
function love.draw()
local delta = love.timer.getAverageDelta()
-- Display the frame time in milliseconds for convenience.
-- A lower frame time means more frames per second.
love.graphics.print(string.format("Average frame time: %.3f ms", 1000 * delta), 0, 0)
fps = love.timer.getFPS( )
love.graphics.print("Current FPS: "..tostring(love.timer.getFPS( )), 0, 15)
love.graphics.print(address, 0, 35)
--see if were getting any messages on the thread channel
local count = love.thread.getChannel('messages'):getCount()
if count then
love.graphics.print(count, 0, 100)
end
if message then
love.graphics.print("Message: "..tostring(message), 0, 60)
elseif ip then
love.graphics.print("IP: "..tostring(ip), 0, 75)
elseif port then
love.graphics.print("Port: "..tonumber(port), 0, 99)
end
end
Code: Select all
local socket = require("socket")
function listen()
local udp = socket.udp()
udp:setsockname ('*', 65000)
-- udp:settimeout(20)
while true do
local message, ip, port = udp:receivefrom()
love.thread.getChannel('messages'):push(message)
love.thread.getChannel('ips'):push(ip)
love.thread.getChannel('ports'):push(port)
end
end
listen()
EDIT: IT WORKED I derped, I saw it flash Message
Code: Select all
function love.update(dt)
local message = love.thread.getChannel('messages'):pop() --set to peek not pop so the first sent it shown
local ip = love.thread.getChannel('ips'):pop()
local port = love.thread.getChannel('ports'):pop()
assert( not err, error )
end
Code: Select all
if message then
love.graphics.print("Message: "..tostring(message), 0, 60)
elseif ip then
love.graphics.print("IP: "..tostring(ip), 0, 75)
elseif port then
love.graphics.print("Port: "..tonumber(port), 0, 99)
end
I've gone over the code to see if I changed anything and it is as posted except the locals wrote above have been removed, I still get a cocat error for the variable result.
EDIT2:
Ok so progress, if I open the server first, then open the client and hit g for it to send then it prints sending on the client window and print the number 7, which i'm assuming is a count of the word "Message". If I don't open the server window first, the client will throw me a concat error.
I'm running both these files on the same computer, would that cause this unexpected behavior?
EDIT3:
I realised that:
Code: Select all
love.graphics.print(""..result..err,50,80)
Code: Select all
love.graphics.print(""..tostring(result)..tostring(err),50,80)
Code: Select all
nilnodename nor servname provide, or not known
Code: Select all
7nil
I feel like I'm getting closer...
FD