Luna as Lua UDP Network Adapter

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
HDPLocust
Citizen
Posts: 65
Joined: Thu Feb 19, 2015 10:56 pm
Location: Swamp
Contact:

Luna as Lua UDP Network Adapter

Post by HDPLocust »

Image

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

Features:
- 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.
Science and violence
User avatar
HDPLocust
Citizen
Posts: 65
Joined: Thu Feb 19, 2015 10:56 pm
Location: Swamp
Contact:

Re: Luna as Lua UDP Network Adapter

Post by HDPLocust »

Oh, suddenly, the sock library (https://love2d.org/forums/viewtopic.php ... f3f9d7199e) already exists, with a similar functionality:)
I'm going to include RUDP here.
Science and violence
Post Reply

Who is online

Users browsing this forum: No registered users and 46 guests