• linux luasocket 使用


    server.lua

    1. #!/usr/bin/lua
    2. local socket = require("socket")
    3. local host, port = "127.0.0.1", 9090
    4. local server = assert(socket.bind(host, port))
    5. local ack = "ack\n"
    6. while true do
    7. print("server: waiting for client connection ...")
    8. local control = assert(server:accept())
    9. while true do
    10. command, status = control:receive()
    11. if status == "closed" then
    12. break
    13. end
    14. print(command)
    15. control:send(ack) -- 注意:发送的数据必须要有结束符才能发送成功
    16. end
    17. end

    client.lua

    1. #! /usr/bin/lua
    2. local socket = require("socket")
    3. local host, port = "127.0.0.1", 9090
    4. local client = assert(socket.connect(host, port))
    5. client:send("GET\n")
    6. while true do
    7. local s, status, partial = client:receive()
    8. print(s)
    9. if status == "closed" then
    10. break
    11. end
    12. client:send("GET\n")
    13. end
    14. 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
     

  • 相关阅读:
    SkiaSharp 之 WPF 自绘 五环弹动球(案例版)
    Gorm 中的钩子和回调
    Redis——zset类型详解
    antd-vue + vue3 实现a-table动态增减行,通过a-from实现a-table行内输入验证
    Pandas数据类型-DataFrame之创建和访问
    学了HTML,快来试着做一份简历吧
    13-ES5和ES6基础
    【考研】数据结构考点——归并排序
    FigDraw 18. SCI 文章绘图之矩形树状图 (treemap)
    MyBatis入门
  • 原文地址:https://blog.csdn.net/q277055799/article/details/126102546