GET

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
the underminer
Posts: 123
Joined: Mon Oct 03, 2005 4:25 am
Location: Netherlands

GET

Post by the underminer »

When I'm using bytesent, it really looks like I only get a response the first time I use this function. I use it like this:

Code: Select all

bytesSent = socket:send(requeststring)
bytesSent = socket:send("User-Agent: SOBrowser\r\n")
bytesSent = socket:send("Host: so.ikhoefgeen.nl\r\n\r\n")
requeststring can be things like
"GET /?id=1 HTTP/1.0 \r\n"
"GET /?test=2 HTTP/1.0\r\n"

For those interested, here's the full function I use for this:

Code: Select all

function GetFile(requeststring,Method,storestring)
	print("Getfile")
	buffer = nil
	data = nil
	filestart =nil
	TimeOut = 0
	if RequestOut then print(requeststring) end
	bytesSent = socket:send(requeststring)
	bytesSent = socket:send("User-Agent: SOBrowser\r\n")
	bytesSent = socket:send("Host: so.ikhoefgeen.nl\r\n\r\n")
	while true do
		buffer = socket:recv()
		if string.len(buffer) > 0 then
			print("buffer filled",buffer)
			if filestart~=1 then
				--print(buffer)
				if string.find(buffer, "\r\n\r\n") then
					data = string.sub(buffer,string.find(buffer, "\r\n\r\n")+4)
					filestart = 1
				end
			else
				data = data..buffer
				--print(data)
				--file:write(buffer)
			end
		else -- probably end of transfer
			TimeOut = TimeOut + 1
			if TimeOut == 50 then
				if data then
					if DataOut == 1 then print(data) end
					if Method == 1 then
						assert(loadstring(storestring.."="..data))()
					elseif Method == 2 then
						file = io.open(storestring,"w+")
						file:write(data)
						file:close()
					end
					GotData = true
				end
				--print(1,LevelData)
				break 
			end
		end
		
		if Controls.read():start() then break end
		--screen.waitVblankStart()
	end
end
The full function call looks like this:

Code: Select all

while not GotData do
	GetFile("GET /?test=2 HTTP/1.0\r\n",1,"LevelData")
end
I've done about 2,5 hours of debugging without result. Could it be a bug in luaplayer 0.16?
Behold! The Underminer got hold of a PSP
the underminer
Posts: 123
Joined: Mon Oct 03, 2005 4:25 am
Location: Netherlands

Post by the underminer »

A friend of mine suggested that the server closes the connection af each request. Can anyone confirm this?. He also hinted that it might be possible to 'keep the connection alive' but he didn't know the details. Can anyone tell me more about this?
Behold! The Underminer got hold of a PSP
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

the underminer wrote:A friend of mine suggested that the server closes the connection af each request. Can anyone confirm this?. He also hinted that it might be possible to 'keep the connection alive' but he didn't know the details. Can anyone tell me more about this?
General description of HTTP1.1: http://www.faqs.org/rfcs/rfc2616.html
a bit of keep-alive headers: http://www.faqs.org/rfcs/rfc2068.html
the underminer
Posts: 123
Joined: Mon Oct 03, 2005 4:25 am
Location: Netherlands

Post by the underminer »

im now reconnecting to a socket everytime I send something, wich works fine and is actually pretty fast
Behold! The Underminer got hold of a PSP
Post Reply