• Stars
    star
    105
  • Rank 328,196 (Top 7 %)
  • Language
    Lua
  • License
    MIT License
  • Created almost 14 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Provides a set of async. callback based handlers for working with raw TCP/UDP socket, ZeroMQ sockets, or HTTP client/server.

lua-handlers

Provides a set of async. callback based handlers for working with raw TCP/UDP socket, ZeroMQ sockets, or HTTP client/server.

Socket connect/listen URI's

Different types of sockets can now be created from URI strings like tcp://localhost:1234/ or tls:/localhost:443/?key=examples/localhost.key&cert=examples/localhost.cert. URI's can be used for connecting sockets or listening sockets.

TCP sockets

tcp://<hostname or ip_address>:<optional port>/

UDP sockets

udp://<hostname or ip_address>:<optional port>/

Unix domain sockets

unix://<path to unix socket>

SSL/TLS sockets over TCP

tls://<hostname or ip_address>:<optional port>/?mode=<client/server>&key=<path to PEM private key>&cert=<path to PEM public certificate>

To force IPv6 sockets

tcp6://<hostname or ipv6_address>:<optional port>/
udp6://<hostname or ipv6_address>:<optional port>/
tls6://<hostname or ipv6_address>:<optional port>/?mode=<client/server>&key=<path to PEM private key>&cert=<path to PEM public certificate>

Example server-side listen URIs:

-- bind tcp socket to 127.0.0.1 on port 80 with an accept backlog of 1000
tcp://localhost:80/?backlog=1000

-- bind tcp socket to IPv6 address 2001:db8::1 on port 80 with an accept backlog of 1000
tcp://[2001:db8::1]:80/?backlog=1000

-- bind TLS wrapped tcp socket to 127.0.0.1 on port 443 with an accept backlog of 1000
-- TLS defaults to mode=server when listening.
tls://localhost:443/?backlog=1000&key=private_key.pem&cert=public_certificate.pem

-- bind Unix domain socket to file /tmp/unix_server.sock
unix:///tmp/unix_server.sock?backlog=100

-- bind udp socket to 127.0.0.1 on port 53
udp://localhost:53

-- bind udp socket to IPv6 loop back address ::1 on port 53
udp://[::1]:53
or
udp6://localhost:53

Example client-side connect URIs:

-- connect tcp socket to 127.0.0.1 on port 80
tcp://localhost:80

-- connect tcp socket to IPv6 address 2001:db8::1 on port 80
tcp://[2001:db8::1]:80

-- connect tcp socket to IPv6 address of hostname ipv6.google.com on port 80
tcp6://ipv6.google.com:80

-- connect TLS wrapped tcp socket to 127.0.0.1 on port 443
-- TLS defaults to mode=client when connecting.
tls://localhost:443

-- connect Unix domain socket to file /tmp/unix_server.sock
unix:///tmp/unix_server.sock

-- connect udp socket to 127.0.0.1 on port 53
udp://localhost:53

-- connect udp socket to IPv6 loop back address ::1 on port 53
udp://[::1]:53
or
udp6://localhost:53

Set local address & port when connecting

Sockets can be bound to a local address & port before connecting to the remote host:port. For connecting URIs add parameters laddr=<local address>&lport=<local port>.

Examples:

-- connect tcp socket to host www.google.com on port 80 and bind the socket to local address 192.168.0.1
tcp://www.google.com/?laddr=192.168.0.1

-- connect tcp socket to host www.google.com on port 80 and bind the socket to local address 192.168.0.1 and local port 16384
tcp://www.google.com/?laddr=192.168.0.1&lport=16384

-- connect udp socket to 10.0.0.10 on port 53 and bind to local address 10.100.100.1 and port 2053
udp://10.0.0.10:53/?laddr=10.100.100.1&lport=2053

Example generic socket server & client

The generic server can listen on any number of sockets with different types. The clients read stdin and send each line to the server which then re-sends the message to all connected clients.

Start generic socket server: lua examples/generic_chat_server.lua tcp://127.0.0.1:1080/ "tls://127.0.0.1:4433/?key=examples/localhost.key&cert=examples/localhost.cert" tcp://[::1]:1082/ unix:///tmp/test.sock?backlog=1234 udp6://localhost:2053

Start generic socket client: lua examples/generic_chat_client.lua tcp://localhost:1080 -- or lua examples/generic_chat_client.lua udp6://localhost:2053 -- or lua examples/generic_chat_client.lua tls://127.0.0.1:4433/ -- or lua examples/generic_chat_client.lua tcp://[::1]:1082/ -- or lua examples/generic_chat_client.lua unix:///tmp/test.sock

Installing

Install base package lua-handler:

luarocks install "https://github.com/brimworks/lua-ev/raw/master/rockspec/lua-ev-scm-1.rockspec"

luarocks install "https://github.com/Neopallium/nixio/raw/master/nixio-scm-0.rockspec"

luarocks install "https://github.com/Neopallium/lua-handlers/raw/master/lua-handler-scm-0.rockspec"

Install optional sub-package lua-handler-http:

luarocks install "https://github.com/brimworks/lua-http-parser/raw/master/lua-http-parser-scm-0.rockspec"

luarocks install "https://github.com/Neopallium/lua-handlers/raw/master/lua-handler-http-scm-0.rockspec"

Install optional sub-package lua-handler-zmq:

luarocks install "https://github.com/Neopallium/lua-zmq/raw/master/rockspecs/lua-zmq-scm-1.rockspec"

luarocks install "https://github.com/Neopallium/lua-handlers/raw/master/lua-handler-zmq-scm-0.rockspec"

Dependencies

Base lua-handler package required dependcies:

Dependencies for optional lua-handler-http package:

Dependencies for optional lua-handler-zmq package:

More Repositories

1

lua-pb

Lua Protocol Buffers
Lua
288
star
2

llvm-lua

Automatically exported from code.google.com/p/llvm-lua
C
152
star
3

lualogging

New maintainer at: https://github.com/lunarmodules/lualogging
Lua
146
star
4

lua-llthreads

Low-Level threads(pthreads or WIN32 threads) for Lua.
C
143
star
5

bevy_water

Dynamic ocean material for Bevy.
Rust
135
star
6

LuaNativeObjects

A Lua bindings generator written in Lua.
Lua
94
star
7

slua

Static lua compiler - Compile Lua code into C code.
C
69
star
8

nixio

System, Networking and I/O library for Lua. This is an unoffical fork of NIXO from: http://luci.subsignal.org/
C
58
star
9

mmap_lowmem

mmap() wrapper to expand MAP_32BIT to use all of the low 4Gbytes of address space.
C
35
star
10

lua-nanomsg

Lua bindings to NanoMsg
Lua
32
star
11

lua-epoll

Lightweight wrapper for epoll.
C
21
star
12

s1vm

Fast Wasm interpreter in Rust
Rust
18
star
13

bevy_shader_graph

Shader graph for Bevy
Rust
18
star
14

lua-clang-cindex

FFI bindings to libclang's CIndex interface.
Lua
12
star
15

websocket-client-go

Reconnecting Websocket Client Golang Library
Go
12
star
16

lua-llnet

A low-level network IO library.
C
12
star
17

lua-buf

Mutable buffer object for Lua.
C
10
star
18

luagit2

LuaGit2 has move to a new home at https://github.com/libgit2/luagit2
Lua
10
star
19

lua-http-tokenizer

A HTTP protocol tokenizer
C
8
star
20

node_engine

Rust
8
star
21

lludp_dissector

Wireshark dissector for the LLUDP protocol
Lua
6
star
22

jpeg2k

Safe wrapper for openjpeg-sys.
Rust
6
star
23

luaxcb

Lua bindings for XCB
C
4
star
24

bevy_fake_interior

Fake interior material for Bevy
WGSL
4
star
25

nft_trader

NFT trader for Polymesh
TypeScript
4
star
26

serialization-benchmarks

Benchmark comparison of C/C++ serialization systems.
C
3
star
27

cr-sys

Rust raw bindings for cr.h: A Simple C Hot Reload Header-only Library
Rust
2
star
28

lua-net-bench

Network service benchmark/stress-testing suite written in Lua.
Lua
2
star
29

mongrel2_stream_prototype

Prototype a stream interface between mongrel2 and backend handlers.
Lua
2
star
30

faxpp

Fast XML Pull Parser
C
2
star
31

sub-script

Scripting interface for substrate nodes.
Rust
2
star
32

cr-rs

Rust safe wrapper for cr.h: A Simple C Hot Reload Header-only Library
Rust
2
star
33

lua-http-message

Fast HTTP message parser for Lua.
Lua
2
star
34

n_closure

header-only C Closure library
C++
2
star
35

pusher-client-go

Pusher Client Go Library
Go
1
star
36

material_designer

Designer for working on Materials/Shaders for Bevy
Rust
1
star
37

openjp2

Rust port of OpenJpeg
C
1
star