WLAN file transfer

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

WLAN file transfer

Post by the underminer »

When you download a file with the method in the example, you'll get a server message, followed by the contents of the file. If I want to print only the contents of the file. The contents are separated from server info by a double enter.("\r\n\r\n"). I do this:

Code: Select all


if string.find(buffer,"\r\n\r\n") then print(string.sub(buffer,string.find(buffer,"\r\n\r\n"))) end 
But it doesn't work. string.find has two outputs, the start and end where it found the "\r\n\r\n". How do I handle this? How can I tell string.sub to use only the first output of find(start position)? And why doesn't it print anything?

I hope I am not too vague
Behold! The Underminer got hold of a PSP
be2003
Posts: 144
Joined: Thu Apr 20, 2006 2:46 pm

Post by be2003 »

this should work:

Code: Select all

datafile = string.sub(buffer, string.find(buffer, "\r\n\r\n", -1))
filename = "file.txt"
file = io.open(filename, "w")
if file then
     file:write(datafile)
     file:close()
end

- be2003
blog
the underminer
Posts: 123
Joined: Mon Oct 03, 2005 4:25 am
Location: Netherlands

Post by the underminer »

I got it working now, but you must leave out -1 in your code
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 »

string.find returns 2 values: start of found pattern and end. How can I tell string.sub to use the last value + 1 ? (I'm now using starting value+4 wich is basicly the same, just curious)
Behold! The Underminer got hold of a PSP
be2003
Posts: 144
Joined: Thu Apr 20, 2006 2:46 pm

Post by be2003 »

i think i put the -1 in the wrong place.... try this....

Code: Select all

datafile = string.sub(buffer, (string.find(buffer, "\r\n\r\n"))+4,-1)
filename = "file.txt" 
file = io.open(filename, "w") 
if file then 
     file:write(datafile) 
     file:close() 
end
i think to do two vlaues you do...(my lua is a little rusty)

Code: Select all

outone, outtwo = string.find(buffer,"\r\n\r\n")
- be2003
blog
the underminer
Posts: 123
Joined: Mon Oct 03, 2005 4:25 am
Location: Netherlands

Post by the underminer »

be2003 wrote:i think i put the -1 in the wrong place.... try this....

Code: Select all

datafile = string.sub(buffer, (string.find(buffer, "\r\n\r\n"))+4,-1)
filename = "file.txt" 
file = io.open(filename, "w") 
if file then 
     file:write(datafile) 
     file:close() 
end
This Is exactly how I've changed it!

For the second code: should work. I'll try it soon
Behold! The Underminer got hold of a PSP
Post Reply