talker.lua 688 B

1234567891011121314151617181920
  1. -----------------------------------------------------------------------------
  2. -- TCP sample: Little program to send text lines to a given host/port
  3. -- LuaSocket sample files
  4. -- Author: Diego Nehab
  5. -----------------------------------------------------------------------------
  6. local socket = require("socket")
  7. host = host or "localhost"
  8. port = port or 8080
  9. if arg then
  10. host = arg[1] or host
  11. port = arg[2] or port
  12. end
  13. print("Attempting connection to host '" ..host.. "' and port " ..port.. "...")
  14. c = assert(socket.connect(host, port))
  15. print("Connected! Please type stuff (empty line to stop):")
  16. l = io.read()
  17. while l and l ~= "" and not e do
  18. assert(c:send(l .. "\n"))
  19. l = io.read()
  20. end