Darkwater

Untitled

Nov 15th, 2011
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.65 KB | None | 0 0
  1. local host = "www.novaember.com"
  2. local file = "/data/test.txt"
  3.  
  4. require("socket.http")
  5.  
  6. local c, count = nil, 0
  7.  
  8. function love.load()
  9.     c = assert(socket.connect(host, 80))
  10.     c:send("GET "..file.." HTTP/1.1\r\nHost: "..host.."\r\n\r\n")
  11.     while true do
  12.         local s, status = receive(c)
  13.         print(s,status)
  14.         count = count + string.len(s or "")
  15.         if status == "closed" then break end
  16.     end
  17.     c:close()
  18.     print(file, count)
  19. end
  20.  
  21. function receive (connection)
  22.     local s, status = connection:receive(2^10)
  23.     if status == "timeout" then
  24.         coroutine.yield(connection)
  25.     end
  26.     return s, status
  27. end
  28.  
Advertisement
Add Comment
Please, Sign In to add comment