zoukankan      html  css  js  c++  java
  • Luasocket 服务器,客户端简单实例

    server.lua

    #!/usr/bin/lua

    local socket = require("socket")

    host, port = "127.0.0.1", 9090

    server = assert(socket.bind(host, port))
    ack = "ack "

    while true
    do
        print("server: waiting for client connection ...")
        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")
    host, port = "127.0.0.1", 9090

    client = assert(socket.connect(host, port))

    client:send("GET ")

    while true
    do
        local s, status, partial = client:receive()
        print(s)
        if status == "closed" then
           break
        end

        client:send("GET ")
    end

    client:close()

    https://www.cnblogs.com/rohens-hbg/p/9014471.html

  • 相关阅读:
    1069.查找学生信息
    1023.Excel排序
    1061.成绩排序
    bzoj 1113
    bzoj 1112 treap树
    bzoj 1225 dfs + 一点点数论
    bzoj 1224
    UESTC
    HDU 3530 单调队列
    bzoj 1233
  • 原文地址:https://www.cnblogs.com/7qin/p/13510454.html
Copyright © 2011-2022 走看看