| View previous topic :: View next topic |
| Author |
Message |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Mon Nov 20, 2006 10:40 pm Post subject: GET |
|
|
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: |
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: | 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: | 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 |
|
| Back to top |
|
 |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Mon Nov 20, 2006 11:20 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Tue Nov 21, 2006 4:17 am Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Sun Nov 26, 2006 1:02 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
|