首先要有相应的socket模块
server.lua
socket = require("socket");
host = host or "127.0.0.1";
port = port or "8888";
server = assert(socket.bind(host, port));
ack = "I'm server , ack\n";
while 1 do
print("server: waiting for client connection...");
control = assert(server:accept());
while 1 do
command,status = control:receive();
if status == "closed" then
break
end
print(command);
control:send(ack);
end
end
client.lua
local socket = require("socket")
host = "127.0.0.1"
port = 8888
--打开一个TCP连接
c = assert (socket.connect (host, port))
c:send ("I'm client,GET \n")
i = 0
while (true) do
local s, status, partial &#