mirror of
https://github.com/lunarmodules/luasocket.git
synced 2025-12-24 05:56:24 +01:00
socket.tcp can accept fd and socket type ('master'(default), 'client')
acceptfd method can be used to write multi-threaded server.
```lua
-- main thread
local fd = srv_sock:acceptfd()
Threads.runfile('echo.lua', fd)
-- echo.lua
local fd = ...
local sock = socket.tcp(fd,'client')
```
or to interact with library such as [ESL](http://wiki.freeswitch.org/wiki/Event_Socket_Library)
```lua
local fd = srv_sock:acceptfd()
Threads.runfile('worker.lua', fd)
-- worker.lua
local sock = ESLconnection((...))
```
If we need just close fd (for example we can not run worker thread) we should call `socket.tcp(fd,'client'):close()`
This provides the automated test scripts used to make sure the library
is working properly.
The files provided are:
testsrvr.lua -- test server
testclnt.lua -- test client
To run these tests, just run lua on the server and then on the client.
hello.lua -- run to verify if installation worked
Good luck,
Diego.