Besides LuaSocket, is there any other library that provides support for the TCP and UDP transport layers for Lua?

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Besides LuaSocket, is there any other library that provides support for the TCP and UDP transport layers for Lua?

孙世龙 sunshilong
Hi, list

Besides LuaSocket, is there any other library that provides support
for the TCP and UDP transport layers for Lua?

I am using vanilla Lua.

Stable and open source project is preferred.
Any guideline or suggestion is welcome.

Thank you for your attention to my question.
Reply | Threaded
Open this post in threaded view
|

Re: Besides LuaSocket, is there any other library that provides support for the TCP and UDP transport layers for Lua?

Adrian Perez de Castro
Hello!

On Wed, 27 Jan 2021 20:59:27 +0800 孙世龙 sunshilong <[hidden email]> wrote:
 
> Besides LuaSocket, is there any other library that provides support
> for the TCP and UDP transport layers for Lua?
>
> I am using vanilla Lua.
>
> Stable and open source project is preferred.
> Any guideline or suggestion is welcome.

I have used cqueues [1] a few times in the past, which worked wonderfully.

(The first time I heard about cqueues was because it is a dependency of
lua-http [2], which I can also recomment and has very nice HTTP/2 support!)

Cheers,
—Adrián


---
[1] http://25thandclement.com/~william/projects/cqueues.html
[2] https://github.com/daurnimator/lua-http

attachment0 (201 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Besides LuaSocket, is there any other library that provides support for the TCP and UDP transport layers for Lua?

Martin Angers
On Wed Jan 27, 2021 at 8:32 AM EST, Adrian Perez de Castro wrote:

> Hello!
>
> On Wed, 27 Jan 2021 20:59:27 +0800 孙世龙 sunshilong
> <[hidden email]> wrote:
>  
> > Besides LuaSocket, is there any other library that provides support
> > for the TCP and UDP transport layers for Lua?
> >
> > I am using vanilla Lua.
> >
> > Stable and open source project is preferred.
> > Any guideline or suggestion is welcome.
>
> I have used cqueues a few times in the past, which worked
> wonderfully.

I second cqueues, it is a great library that provides a full
non-blocking environment for networking (using coroutines and
kqueue/epoll), but note that it is POSIX only.

For something smaller in scope and features, I implemented a Lua wrapper
[1] around the socket99 C library [2], it provides a nice API to sockets
(POSIX-only too)

[1]: https://git.sr.ht/~mna/luasock99
[2]: https://github.com/silentbicycle/socket99
Reply | Threaded
Open this post in threaded view
|

Re: Besides LuaSocket, is there any other library that provides support for the TCP and UDP transport layers for Lua?

Rob Kendrick-2
In reply to this post by 孙世龙 sunshilong
On Wed, Jan 27, 2021 at 08:59:27PM +0800, 孙世龙 sunshilong wrote:
> Hi, list
>
> Besides LuaSocket, is there any other library that provides support
> for the TCP and UDP transport layers for Lua?
>
> I am using vanilla Lua.
>
> Stable and open source project is preferred.
> Any guideline or suggestion is welcome.

Years ago I wrote a library trying to bind much of POSIX for a project,
and it included networking support.  Daniel Silverstone took over
maintenance as part of his git server project.  A brief tour of the
high-level interface (there are also low-level bindings to the calls)
can be seen here https://www.rjek.com/luxio-tour.txt

The project is now here https://git.gitano.org.uk/luxio.git/tree/ but I
no longer have much to do with it.

It might cover a bit too much for your taste and needs, as well as being
POSIX-specific.

B.
Reply | Threaded
Open this post in threaded view
|

Re: Besides LuaSocket, is there any other library that provides support for the TCP and UDP transport layers for Lua?

Soni "They/Them" L.
In reply to this post by 孙世龙 sunshilong


On 2021-01-27 9:59 a.m., 孙世龙 sunshilong wrote:

> Hi, list
>
> Besides LuaSocket, is there any other library that provides support
> for the TCP and UDP transport layers for Lua?
>
> I am using vanilla Lua.
>
> Stable and open source project is preferred.
> Any guideline or suggestion is welcome.
>
> Thank you for your attention to my question.

luv should be compatible with vanilla lua https://github.com/luvit/luv
Reply | Threaded
Open this post in threaded view
|

Re: Besides LuaSocket, is there any other library that provides support for the TCP and UDP transport layers for Lua?

Sean Conner
In reply to this post by 孙世龙 sunshilong
It was thus said that the Great 孙世龙 sunshilong once stated:
> Hi, list
>
> Besides LuaSocket, is there any other library that provides support
> for the TCP and UDP transport layers for Lua?
>
> I am using vanilla Lua.
>
> Stable and open source project is preferred.
> Any guideline or suggestion is welcome.

  I wrote my own [1].  At the lowest level, I have org.conman.net, which
supports making TCP, UDP, raw (if you call the functions correctly) and Unix
sockets.  It also supports both IPv4 and IPv6 but this module is pretty low
level.

  Stepping up one level, I have org.conman.net.tcp and org.conman.net.tls,
which gives back a Lua file-like object that support read() and write() you
would expect.  And yes, there is TLS support, but it requires libtls [2].

  And if you want to write an event based server, I have org.conman.nfl.tcp
and org.conman.nfl.tls, which handle each connection in a coroutine.  I have
two projects that use this, one for TCP [3] and one for TLS [4][5].

  This code has been written for POSIX systems.

  -spc

[1] Everything I mention is available here:

        https://github.com/spc476/lua-conmanorg

[2] A version for OpenSSL: https://causal.agency/libretls/

[3] Starting here, which shows the main loop of each coroutine and how
        to run the main event loop.  This is for TCP:

        https://github.com/spc476/port70/blob/1d59a312fde53219e303504febc6013f3991baff/port70.lua#L141

[4] Starting here, which shows the main loop of each coroutine and how
        to run the main event loop.  This is for TLS:

        https://github.com/spc476/GLV-1.12556/blob/d2e32f97dd882670e206f57765425ee6c8d183ab/Lua/GLV-1.12556.lua#L288

[5] The list of modules used and what they do:

        org.conman.net   - low level socket and IP address code
        org.conman.net.tcp - blocking IO for TCP connections
        org.conman.net.tls - blocking IO for TLS connections
        org.conman.net.ios - provides a Lua file-like object API (also used
                             for the non-blocking IO routines)
        org.conman.nfl     - main event driver
        org.conman.nfl.tcp - event driven IO for TCP connections
        org.conman.nfl.tls - event driven IO for TLS connections
        org.conman.pollset - select/poll/epoll/kqueue interface (same API
                             presented for all backends)
        org.conman.tls     - wrapper around libtls

        There are some other modules used, but those are the main ones
        centered around network activity.
v
Reply | Threaded
Open this post in threaded view
|

Re: Besides LuaSocket, is there any other library that provides support for the TCP and UDP transport layers for Lua?

v
In reply to this post by 孙世龙 sunshilong
On Wed, 2021-01-27 at 20:59 +0800, 孙世龙 sunshilong wrote:

> Hi, list
>
> Besides LuaSocket, is there any other library that provides support
> for the TCP and UDP transport layers for Lua?
>
> I am using vanilla Lua.
>
> Stable and open source project is preferred.
> Any guideline or suggestion is welcome.
>
> Thank you for your attention to my question.

I often use lgi, the Lua bingings to GLib and Gio (and other libraries
that support GObject Introspection, including Gtk). While it is
probably a huge overkill for simpler programs, it integrates really
well into Lua thanks to coroutines-based async operations and works
well on bigger projects.
Since lgi includes a lot of functional, this way networkning will play
nicely together with all of it, including file I/O, GUI via Gtk and
other ones.
--
v <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Besides LuaSocket, is there any other library that provides support for the TCP and UDP transport layers for Lua?

孙世龙 sunshilong
In reply to this post by Sean Conner
Sean Conner >And yes, there is TLS support, but it requires libtls [2].
Is there any method that could easily disable TLS?

On Thu, Jan 28, 2021 at 5:56 AM Sean Conner <[hidden email]> wrote:

>
> It was thus said that the Great 孙世龙 sunshilong once stated:
> > Hi, list
> >
> > Besides LuaSocket, is there any other library that provides support
> > for the TCP and UDP transport layers for Lua?
> >
> > I am using vanilla Lua.
> >
> > Stable and open source project is preferred.
> > Any guideline or suggestion is welcome.
>
>   I wrote my own [1].  At the lowest level, I have org.conman.net, which
> supports making TCP, UDP, raw (if you call the functions correctly) and Unix
> sockets.  It also supports both IPv4 and IPv6 but this module is pretty low
> level.
>
>   Stepping up one level, I have org.conman.net.tcp and org.conman.net.tls,
> which gives back a Lua file-like object that support read() and write() you
> would expect.  And yes, there is TLS support, but it requires libtls [2].
>
>   And if you want to write an event based server, I have org.conman.nfl.tcp
> and org.conman.nfl.tls, which handle each connection in a coroutine.  I have
> two projects that use this, one for TCP [3] and one for TLS [4][5].
>
>   This code has been written for POSIX systems.
>
>   -spc
>
> [1]     Everything I mention is available here:
>
>         https://github.com/spc476/lua-conmanorg
>
> [2]     A version for OpenSSL: https://causal.agency/libretls/
>
> [3]     Starting here, which shows the main loop of each coroutine and how
>         to run the main event loop.  This is for TCP:
>
>         https://github.com/spc476/port70/blob/1d59a312fde53219e303504febc6013f3991baff/port70.lua#L141
>
> [4]     Starting here, which shows the main loop of each coroutine and how
>         to run the main event loop.  This is for TLS:
>
>         https://github.com/spc476/GLV-1.12556/blob/d2e32f97dd882670e206f57765425ee6c8d183ab/Lua/GLV-1.12556.lua#L288
>
> [5]     The list of modules used and what they do:
>
>         org.conman.net     - low level socket and IP address code
>         org.conman.net.tcp - blocking IO for TCP connections
>         org.conman.net.tls - blocking IO for TLS connections
>         org.conman.net.ios - provides a Lua file-like object API (also used
>                              for the non-blocking IO routines)
>         org.conman.nfl     - main event driver
>         org.conman.nfl.tcp - event driven IO for TCP connections
>         org.conman.nfl.tls - event driven IO for TLS connections
>         org.conman.pollset - select/poll/epoll/kqueue interface (same API
>                              presented for all backends)
>         org.conman.tls     - wrapper around libtls
>
>         There are some other modules used, but those are the main ones
>         centered around network activity.
Reply | Threaded
Open this post in threaded view
|

Re: Besides LuaSocket, is there any other library that provides support for the TCP and UDP transport layers for Lua?

Sam Putman
In reply to this post by 孙世龙 sunshilong


On Wed, Jan 27, 2021 at 3:00 AM 孙世龙 sunshilong <[hidden email]> wrote:
Hi, list

Besides LuaSocket, is there any other library that provides support
for the TCP and UDP transport layers for Lua?

I am using vanilla Lua.

Stable and open source project is preferred.
Any guideline or suggestion is welcome.

Thank you for your attention to my question.

We've been very happy with luv, which provides Lua bindings to the libuv event loop.

If you want an event loop, async, callback-style program, it's an excellent choice.

You can wrap callbacks inside a coroutine, by executing the call to e.g. a TCP fetch, yielding,
then resuming the coroutine inside the callback, like this (example from Tim Caswell):

local function sleep(ms, answer)
  local co = coroutine.running()
  local timer = uv.new_timer()
  timer:start(ms, 0, function ()
    timer:close()
    return coroutine.resume(co, answer)
  end)
  return coroutine.yield()
end

-- Using it would look like:

coroutine.wrap(function ()
  print "Getting answer to everything..."
  local answer = sleep(1000, 42)
  print("Answer is", answer)
end)()

which gives a nice imperative style to non-blocking code.

cheers,
-Sam.
Reply | Threaded
Open this post in threaded view
|

Re: Besides LuaSocket, is there any other library that provides support for the TCP and UDP transport layers for Lua?

孙世龙 sunshilong
In reply to this post by Martin Angers
Adrian Perez de Castro >I have used cqueues [1] a few times in the
past, which worked wonderfully.
Martin Angers                > I second cqueues.
Thanks to both of you.
It's a pity that cqueues could not support both Windows and Linux.

On Wed, Jan 27, 2021 at 9:50 PM Martin Angers <[hidden email]> wrote:

>
> On Wed Jan 27, 2021 at 8:32 AM EST, Adrian Perez de Castro wrote:
> > Hello!
> >
> > On Wed, 27 Jan 2021 20:59:27 +0800 孙世龙 sunshilong
> > <[hidden email]> wrote:
> >
> > > Besides LuaSocket, is there any other library that provides support
> > > for the TCP and UDP transport layers for Lua?
> > >
> > > I am using vanilla Lua.
> > >
> > > Stable and open source project is preferred.
> > > Any guideline or suggestion is welcome.
> >
> > I have used cqueues a few times in the past, which worked
> > wonderfully.
>
> I second cqueues, it is a great library that provides a full
> non-blocking environment for networking (using coroutines and
> kqueue/epoll), but note that it is POSIX only.
>
> For something smaller in scope and features, I implemented a Lua wrapper
> [1] around the socket99 C library [2], it provides a nice API to sockets
> (POSIX-only too)
>
> [1]: https://git.sr.ht/~mna/luasock99
> [2]: https://github.com/silentbicycle/socket99
Reply | Threaded
Open this post in threaded view
|

Re: Besides LuaSocket, is there any other library that provides support for the TCP and UDP transport layers for Lua?

孙世龙 sunshilong
In reply to this post by Sam Putman
>We've been very happy with luv, which provides Lua bindings to the libuv event loop.
Thank you for your detailed explanation.
It seems that luv itself doesn't provide support for TCP or UDP.

Best regards
sunshilong

On Thu, Jan 28, 2021 at 9:36 AM Sam Putman <[hidden email]> wrote:

>
>
>
> On Wed, Jan 27, 2021 at 3:00 AM 孙世龙 sunshilong <[hidden email]> wrote:
>>
>> Hi, list
>>
>> Besides LuaSocket, is there any other library that provides support
>> for the TCP and UDP transport layers for Lua?
>>
>> I am using vanilla Lua.
>>
>> Stable and open source project is preferred.
>> Any guideline or suggestion is welcome.
>>
>> Thank you for your attention to my question.
>
>
> We've been very happy with luv, which provides Lua bindings to the libuv event loop.
>
> If you want an event loop, async, callback-style program, it's an excellent choice.
>
> You can wrap callbacks inside a coroutine, by executing the call to e.g. a TCP fetch, yielding,
> then resuming the coroutine inside the callback, like this (example from Tim Caswell):
>
> local function sleep(ms, answer)
>   local co = coroutine.running()
>   local timer = uv.new_timer()
>   timer:start(ms, 0, function ()
>     timer:close()
>     return coroutine.resume(co, answer)
>   end)
>   return coroutine.yield()
> end
>
> -- Using it would look like:
>
> coroutine.wrap(function ()
>   print "Getting answer to everything..."
>   local answer = sleep(1000, 42)
>   print("Answer is", answer)
> end)()
>
> which gives a nice imperative style to non-blocking code.
>
> cheers,
> -Sam.
Reply | Threaded
Open this post in threaded view
|

Re: Besides LuaSocket, is there any other library that provides support for the TCP and UDP transport layers for Lua?

Sean Conner
In reply to this post by 孙世龙 sunshilong
It was thus said that the Great 孙世龙 sunshilong once stated:
> Sean Conner >And yes, there is TLS support, but it requires libtls [2].
> Is there any method that could easily disable TLS?

  Um ... don't use the TLS modules?  I'm not sure what you're asking here.

  -spc
Reply | Threaded
Open this post in threaded view
|

Re: Besides LuaSocket, is there any other library that provides support for the TCP and UDP transport layers for Lua?

孙世龙 sunshilong
 t was thus said that the Great Sean Conner once stated:
>>And yes, there is TLS support, but it requires libtls [2].
>> Is there any method that could easily disable TLS?

>Um ... don't use the TLS modules?  I'm not sure what you're asking here.
As per the document(https://github.com/bob-beck/libtls/blob/master/TUTORIAL.md),
which says that:
libtls is shipped as part of libressl with OpenBSD. It is designed to
be simpler to use than other C based TLS interfaces (especially native
OpenSSL) to do "normal" things with TLS in programs.

I don't need to encrypt the data transported through TCP/UDP and
disabling TLS support may speed up the program.
So I wonder that whether there is a simple method to disable TLS
support for lua-conmanorg (which is written by you)?

Best regards
sunshilong

On Thu, Jan 28, 2021 at 10:29 AM Sean Conner <[hidden email]> wrote:
>
> It was thus said that the Great 孙世龙 sunshilong once stated:
> > Sean Conner >And yes, there is TLS support, but it requires libtls [2].
> > Is there any method that could easily disable TLS?
>
>   Um ... don't use the TLS modules?  I'm not sure what you're asking here.
>
>   -spc
Reply | Threaded
Open this post in threaded view
|

Re: Besides LuaSocket, is there any other library that provides support for the TCP and UDP transport layers for Lua?

Sean Conner
It was thus said that the Great 孙世龙 sunshilong once stated:

>  t was thus said that the Great Sean Conner once stated:
> >>And yes, there is TLS support, but it requires libtls [2].
> >> Is there any method that could easily disable TLS?
>
> >Um ... don't use the TLS modules?  I'm not sure what you're asking here.
> As per the document(https://github.com/bob-beck/libtls/blob/master/TUTORIAL.md),
> which says that:
> libtls is shipped as part of libressl with OpenBSD. It is designed to
> be simpler to use than other C based TLS interfaces (especially native
> OpenSSL) to do "normal" things with TLS in programs.
>
> I don't need to encrypt the data transported through TCP/UDP and
> disabling TLS support may speed up the program.
> So I wonder that whether there is a simple method to disable TLS
> support for lua-conmanorg (which is written by you)?

  Seriously, don't use the following modules:

        org.conman.tls
        org.conman.net.tls
        org.conman.nfl.tls

  That's it.  You can modify the makefile to omit building and intalling
these files.  Yes, I don't have a "don't build these" target in the
makefile, but I'm not going to dig into the autoconf mess just for this.

  -spc
Reply | Threaded
Open this post in threaded view
|

Re: Besides LuaSocket, is there any other library that provides support for the TCP and UDP transport layers for Lua?

Michal Kottman
In reply to this post by 孙世龙 sunshilong
On Thu, Jan 28, 2021, 03:08 孙世龙 sunshilong <[hidden email]> wrote:
It seems that luv itself doesn't provide support for TCP or UDP.


That said, it does require you to set up your code with an event loop / callback style (yes, you can use coro-style APIs).