server.lua

#!/usr/bin/lua

local socket = require("socket")

host, port = "127.0.0.1", 9090

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

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\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()

 

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

相关文章:

  • 2018-03-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
猜你喜欢
  • 2022-01-29
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
  • 2021-11-23
  • 2022-12-23
  • 2022-01-17
相关资源
相似解决方案