testsrvr.lua 525 B

1234567891011121314151617181920
  1. socket = require("socket");
  2. host = host or "localhost";
  3. port = port or "8383";
  4. server = assert(socket.bind(host, port));
  5. ack = "\n";
  6. while 1 do
  7. print("server: waiting for client connection...");
  8. control = assert(server:accept());
  9. while 1 do
  10. command, emsg = control:receive();
  11. if emsg == "closed" then
  12. control:close()
  13. break
  14. end
  15. assert(command, emsg)
  16. assert(control:send(ack));
  17. print(command);
  18. ((loadstring or load)(command))();
  19. end
  20. end