This lib provides connections and async-loops for fast-and-easy game networking, based on callbacks and other stuff.
There no servers and clients, only "connections", but you can bind manager to any port.
Using like:
Code: Select all
luna = require'luna'(7777)
luna:setCallback(
'love lua',
function(connection, data)
if data.value = 'i love lua so much' then
connection:send({value = 'Me too!'}, 'me too')
end
)
luna:setCallback(
'me too',
function(connection, data)
if data.value = 'Me too' then
print('Obey for Love!')
end
)
connect = luna:connect('localhost', 7777)
connect:send({value = 'i love lua so much'}, 'love lua')
while true do
-- event loop and message iteration
for data, ip, port in luna:receive() do print(data, ip, port) end
end
- Automatic connect/disconnect/ping/status/disconnect by timeout etc;
- Callbacks for everything! And for service callbacks too;
- JSON as package protocol, send tables!;
- UDP as transport protocol;
- You can transfer any data in any application protocol: every message, not consumed by callbacks, going to iterator as raw "data" "ip" and "port", useful for NAT PMP by udp, master-server linking etc.
There is one significant limitation: luasocket transfer UDP messages less then 8kb. Your table/data must be less then 8k in json-packed form. Later I'll make a nice RUDP lib and solve it.
Repo, reference and more complex example:
https://bitbucket.org/MainTomato/toolch ... ?at=master
P.S. I was inspired by the lube and node.js to develop this thing, maybe useful not only for me.