daytimeclnt.lua 698 B

12345678910111213141516171819202122
  1. -----------------------------------------------------------------------------
  2. -- UDP sample: daytime protocol client
  3. -- LuaSocket sample files
  4. -- Author: Diego Nehab
  5. -----------------------------------------------------------------------------
  6. local socket = require"socket"
  7. host = host or "127.0.0.1"
  8. port = port or 13
  9. if arg then
  10. host = arg[1] or host
  11. port = arg[2] or port
  12. end
  13. host = socket.dns.toip(host)
  14. udp = socket.udp()
  15. print("Using host '" ..host.. "' and port " ..port.. "...")
  16. udp:setpeername(host, port)
  17. udp:settimeout(3)
  18. sent, err = udp:send("anything")
  19. if err then print(err) os.exit() end
  20. dgram, err = udp:receive()
  21. if not dgram then print(err) os.exit() end
  22. io.write(dgram)