Changes from ages ago
This commit is contained in:
parent
e2503cf103
commit
50a6cf88f4
31
client.lua
31
client.lua
@ -3,19 +3,40 @@ local net = require("lnet.tcp")
|
|||||||
local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
|
|
||||||
local http = require("lnet.http")
|
local http = require("lnet.http")
|
||||||
|
--local https = require("lnet.https")
|
||||||
|
local https = require("ssl.https")
|
||||||
|
|
||||||
multi:newThread("Download Test",function()
|
-- multi:newThread("Download Test",function()
|
||||||
local data = http.request("http://zjcdn.mangafox.me/store/manga/14765/01-001.0/compressed/t001.jpg")
|
-- http.request:holdMe(false) -- Gain Access to the return manager
|
||||||
|
-- local data = http.request {
|
||||||
|
-- url = "http://files.luaforge.net/releases/luaforwindows/luaforwindows/5.1.4-35/LuaForWindows_v5.1.4-35.exe",
|
||||||
|
-- sink = ltn12.sink.file(io.open("test.exe","wb"))
|
||||||
|
-- }
|
||||||
|
-- local t={}
|
||||||
|
-- data.OnStatus(function(part,whole)
|
||||||
|
-- local per = math.ceil((part/whole)*100)
|
||||||
|
-- if not t[per] then
|
||||||
|
-- print("T1",per)
|
||||||
|
-- t[per] = true
|
||||||
|
-- end
|
||||||
|
-- end)
|
||||||
|
-- local c = os.clock()
|
||||||
|
-- thread.hold(data.connect())
|
||||||
|
-- print("Done!",os.clock()-c)
|
||||||
|
-- end)
|
||||||
|
|
||||||
|
multi:newThread("Download Test 2",function()--https://erowall.com/download_img.php?dimg=16911&raz=2560x1600
|
||||||
|
local data,err = https.request("https://erowall.com/download_img.php?dimg=16911&raz=2560x1600")
|
||||||
local file = io.open("test.jpg","wb")
|
local file = io.open("test.jpg","wb")
|
||||||
file:write(data)
|
file:write(data)
|
||||||
file:flush()
|
file:flush()
|
||||||
file:close()
|
file:close()
|
||||||
|
print("Done!")
|
||||||
os.exit()
|
os.exit()
|
||||||
|
end).OnError(function(self,err)
|
||||||
|
print(">>",err)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
multi:newThread("Timer",function()
|
|
||||||
|
|
||||||
end)
|
|
||||||
-- local client = net.newCastedClient("Test")--net:newTCPClient("localhost",12345)
|
-- local client = net.newCastedClient("Test")--net:newTCPClient("localhost",12345)
|
||||||
|
|
||||||
-- client:send("Test!")
|
-- client:send("Test!")
|
||||||
|
|||||||
@ -174,6 +174,7 @@ function metat.__index:receivebody(headers, sink, step)
|
|||||||
for i=1,math.floor(length/default_block_size) do
|
for i=1,math.floor(length/default_block_size) do
|
||||||
thread.yield()
|
thread.yield()
|
||||||
ret = self.try(ltn12.pump.step(socket.source(mode, self.c, default_block_size), sink, step))
|
ret = self.try(ltn12.pump.step(socket.source(mode, self.c, default_block_size), sink, step))
|
||||||
|
thread.pushStatus(i,math.floor(length/default_block_size))
|
||||||
end
|
end
|
||||||
if lp~=0 then
|
if lp~=0 then
|
||||||
ret = self.try(ltn12.pump.step(socket.source(mode, self.c, lp), sink, step))
|
ret = self.try(ltn12.pump.step(socket.source(mode, self.c, lp), sink, step))
|
||||||
@ -301,7 +302,7 @@ local trequest, tredirect
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- We don't need to protect this function the thread:newFunction wrapper handles errors for us
|
-- We don't need to protect this function the thread:newFunction wrapper handles errors for us
|
||||||
trequest = thread:newFunction(function(reqt)
|
function trequest(reqt)
|
||||||
-- we loop until we get what we want, or
|
-- we loop until we get what we want, or
|
||||||
-- until we are sure there is no way to get it
|
-- until we are sure there is no way to get it
|
||||||
local nreqt = adjustrequest(reqt)
|
local nreqt = adjustrequest(reqt)
|
||||||
@ -338,7 +339,7 @@ trequest = thread:newFunction(function(reqt)
|
|||||||
end
|
end
|
||||||
h:close()
|
h:close()
|
||||||
return 1, code, headers, status
|
return 1, code, headers, status
|
||||||
end,true)
|
end
|
||||||
|
|
||||||
local function srequest(u, b)
|
local function srequest(u, b)
|
||||||
local t = {}
|
local t = {}
|
||||||
@ -363,9 +364,9 @@ local function srequest(u, b)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
_M.request = function(reqt, body)
|
_M.request = thread:newFunction(function(reqt, body)
|
||||||
if base.type(reqt) == "string" then return srequest(reqt, body)
|
if base.type(reqt) == "string" then return srequest(reqt, body)
|
||||||
else return trequest(reqt) end
|
else return trequest(reqt) end
|
||||||
end
|
end,true)
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
@ -9,7 +9,7 @@
|
|||||||
local socket = require("socket")
|
local socket = require("socket")
|
||||||
local ssl = require("ssl")
|
local ssl = require("ssl")
|
||||||
local ltn12 = require("ltn12")
|
local ltn12 = require("ltn12")
|
||||||
local http = require("lnet.http") -- Only real change that was needed to get things working
|
local http = require("lnet.http")
|
||||||
local url = require("socket.url")
|
local url = require("socket.url")
|
||||||
|
|
||||||
local try = socket.try
|
local try = socket.try
|
||||||
@ -143,4 +143,4 @@ end
|
|||||||
_M.request = request
|
_M.request = request
|
||||||
_M.tcp = tcp
|
_M.tcp = tcp
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
Loading…
x
Reference in New Issue
Block a user