server.lua
- #!/usr/bin/lua
-
- local socket = require("socket")
- local host, port = "127.0.0.1", 9090
- local server = assert(socket.bind(host, port))
- local ack = "ack\n"
-
- while true do
- print("server: waiting for client connection ...")
- local control = assert(server:accept())
- while true do
- command, status = control:receive()
- if status == "closed" then
- break
- end
- print(command)
- control:send(ack) -- 注意:发送的数据必须要有结束符才能发送成功
- end
- end
client.lua
- #! /usr/bin/lua
-
- local socket = require("socket")
- local host, port = "127.0.0.1", 9090
- local client = assert(socket.connect(host, port))
- client:send("GET\n")
-
- while true do
- local s, status, partial = client:receive()
- print(s)
- if status == "closed" then
- break
- end
- client:send("GET\n")
- end
-
- client:close()
参考资料
#!/usr/bin/env bash
##一键安装lua5.3 和 luarocks 脚本
cd /usr/local
wget http://www.lua.org/ftp/lua-5.3.3.tar.gz\
&& tar -zxvf lua-5.3.3.tar.gz\
&&cd lua-5.3.3
#支持的平台:aix bsd c89 freebsd generic linux macosx mingw posix solaris
#我这里是centos 所以是make linux ,其他平台自行修改,例如osx: make macosx
make linux && make test && make install && make local\
&&echo "重新安装luarocks"
if [ ! -d "/usr/local/luarocks-2.4.1" ];then
cd /usr/local && wget http://luarocks.org/releases/luarocks-2.4.1.tar.gz && tar -zxvf luarocks-2.4.1.tar.gz
else
echo "/usr/local/luarocks-2.4.1 文件夹已经存在"
fi
cd /usr/local/luarocks-2.4.1
./configure --with-lua=/usr/local --with-lua-include=/usr/local/lua-5.3.3/include\
&&make build && make install && make bootstrap
source ~/.bash_profile
echo "测试luarocks安装lockbox"
luarocks install lockbox
lua -v
linux 安装lua支持
http://www.lua.org/ftp/
https://www.csdn.net/tags/NtDaIgwsMzY2NjctYmxvZwO0O0OO0O0O.html
linux下安装luarocks
https://luarocks.github.io/luarocks/releases/
https://www.jianshu.com/p/500984a2d1a5
https://blog.csdn.net/weixin_33862993/article/details/91672482
https://cloud.tencent.com/developer/article/1546454
https://blog.csdn.net/weixin_32537261/article/details/116875985
Lua在Linux上找不到LuaRocks安装的模块
https://www.jb51.cc/lua/727837.html
运行
luarocks install luasocket 错误解决
Warning: Failed searching manifest: Failed fetching manifest for https://luarocks.org
ping luarocks.org
vi /etc/hosts
45.33.61.132 luarocks.org
luarocks list
查看安装列表
怎么用命令运行lua文本文件
写好脚本script.lua,然后在控制台(cmd)下输入Lua script.lua,
linux lua socket编程,lua 中 socket 通信示例
https://blog.csdn.net/weixin_39861627/article/details/116970462