I can set up a server and client (UDP) fine, the server recognises the connection of the client and anything the client sends (which, at the moment, is redirected out the stdout).
The issue is that the client doesn't seem to receive any of the server's messages (both sent via server:send(msg) and server:send(msg, clientid))
Here's the server Lua:
Code: Select all
local Class = require "lib.class"
require "lib.LUBE"
require "player"
port = 8720
universe = {}
local server, numplayers
function love.load()
print("SERVER BEGIN")
numplayers = 0
server = lube.udpServer()
server.handshake = "space-cowboy"
server:setPing(true, 15, "ping")
server:listen(port)
print("listening on",port)
server.callbacks.recv = function(d, id) onReceive(d, id) end
server.callbacks.connect = function(id) onConnect(id) end
server.callbacks.disconnect = function(id) onDisconnect(id) end
end
function love.update(dt)
server:update(dt)
end
function onReceive(data, clientid)
print(clientid, data)
server:send("HELLO THERE", clientid)
end
function onConnect(clientid)
print("CON",clientid)
end
function onDisconnect(clientid)
print("DISCON",clientid)
end
Code: Select all
local Vector = require "lib.vector"
local Class = require "lib.class"
require "lib.LUBE"
require "player"
local client
-- client = lube.udpClient()
universe = {}
t = 0
tickrate = 5
function love.load()
love.graphics.setBackgroundColor(33, 89, 125)
ship = {}
ship.img = love.graphics.newImage("media/ship.png")
ship.img:setFilter("linear", "nearest")
ship.w = ship.img:getWidth()
ship.h = ship.img:getHeight()
local cfg = love.filesystem.read("userconfig.cfg")
local ip, port = cfg:match("^(.+):(%d+)$")
assert(ip and port)
client = lube.udpClient()
client.handshake = "space-cowboy"
client:setPing(true, 5, "ping")
client.callbacks.recv = function(d) onReceive(d) end
assert(client:connect(ip, port, true))
print(ip, port)
end
function love.update(dt)
client:update(dt)
t = t + dt
if t > tickrate then
client:send("Hello?")
print(">Hello?")
t = t - tickrate
end
end
function love.draw()
for k,v in pairs(universe) do
if v.loaded then
v:draw(ship)
end
end
end
function onReceive(data)
print(data)
end
If anyone could kindly point out where I'm going wrong with the server/client that might just be causing either the server to not send messages (to the right place?) or the client to not receive them, it'd be much appreciated!
EDIT:
Stay tuned, I think I've solved it.
LUBE needs port as a number (and accepts a string perfectly fine, and will even connect with a string - but won't listen for any messages from the server side, much to my confusion).