Skip to content

Example: Sending Data To The Server Once

Seppi edited this page May 29, 2018 · 4 revisions

To send data to the server once, we send information to the server to process.

In this example, we will inform the server what our name is.

For the server:

lovernetlib = require('lovernet')
lovernet = lovernetlib.new{type=lovernetlib.mode.server}
lovernet:addOp('whoami')
lovernet:addValidateOnServer('whoami',{name='string'})
lovernet:addProcessOnServer('whoami',function(self,peer,arg,storage)
  local user = self:getUser(peer)
  user.name = arg.name
end)

function love.update(dt)
  lovernet:update(dt)
end

For the client:

lovernetlib = require('lovernet')
lovernet = lovernetlib.new()
lovernet:addOp('whoami')

lovernet:pushData('whoami',{name='Dennis Ritchie'})

function love.update(dt)
  lovernet:update(dt)
end