forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

WLAN file transfer

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
the underminer



Joined: 03 Oct 2005
Posts: 124
Location: Netherlands

PostPosted: Thu Nov 02, 2006 6:21 am    Post subject: WLAN file transfer Reply with quote

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:


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
Back to top
View user's profile Send private message
be2003



Joined: 20 Apr 2006
Posts: 144

PostPosted: Thu Nov 02, 2006 12:36 pm    Post subject: Reply with quote

this should work:

Code:

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
Back to top
View user's profile Send private message
the underminer



Joined: 03 Oct 2005
Posts: 124
Location: Netherlands

PostPosted: Fri Nov 03, 2006 12:36 am    Post subject: Reply with quote

I got it working now, but you must leave out -1 in your code
_________________
Behold! The Underminer got hold of a PSP
Back to top
View user's profile Send private message
the underminer



Joined: 03 Oct 2005
Posts: 124
Location: Netherlands

PostPosted: Fri Nov 03, 2006 12:39 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
be2003



Joined: 20 Apr 2006
Posts: 144

PostPosted: Fri Nov 03, 2006 2:25 pm    Post subject: Reply with quote

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

Code:

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:

outone, outtwo = string.find(buffer,"\r\n\r\n")

_________________
- be2003
blog
Back to top
View user's profile Send private message
the underminer



Joined: 03 Oct 2005
Posts: 124
Location: Netherlands

PostPosted: Sat Nov 04, 2006 9:04 pm    Post subject: Reply with quote

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

Code:

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group