Lua编译
- 下载,http://www.lua.org/download.html
make clean all linux
sudo make install
LuaSocket编译
sudo git clone https://github.com/diegonehab/luasocket
cd luasocket
sudo make clean all install LUAV=5.3
使用范例
包引用
local socket = require("socket")
连接
服务端
1 | host = "*" |
客户端
1 | host = "localhost" |
接受/发送
接收端
1 | l, e = client:receive() |
发送端
1 | str = "hello" |
其他接口
setoption(option [, value])
:进行keepalive等设置client:shutdown(mode)
:mode = [both/send/receive],关闭全双工连接的全部或部分
luaSocket其他功能
- DNS
- FTP
- HTTP
- LTN12
- MIME
- SMTP
- UDP
- URL
测试代码
Listener.lua
1 | local socket = require("socket") |
Talker.lua
1 | local socket = require("socket") |