-
Notifications
You must be signed in to change notification settings - Fork 4
Example: Sending Latest Data To Client
Seppi edited this page May 20, 2018
·
3 revisions
To get the latest data for a client, we send an empty request every update and simply poll the data that we want.
In this example, we will see how many users are connected to the server.
For the server:
lovernetlib = require('lovernet')
lovernet = lovernetlib.new{type=lovernetlib.mode.server}
lovernet:addOp('q') -- (q)uery .. use single character to reduce bandwidth
lovernet:addProcessOnServer('q',function(self,peer,arg,storage)
local count = 0
for user_index,user in pairs(self:getUsers()) do
count = count + 1
end
return count
end)
function love.update(dt)
lovernet:update(dt)
endFor the client:
lovernetlib = require('lovernet')
lovernet = lovernetlib.new()
lovernet:addOp('q')
function love.update(dt)
lovernet:pushData('q')
lovernet:update(dt)
end
function love.draw()
if lovernet:getCache('q') then
love.graphics.print('Connected users:'..lovernet:getCache('q'))
end
end