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 

Sending binary data over WLAN

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



Joined: 07 Dec 2005
Posts: 16

PostPosted: Wed Dec 07, 2005 4:54 pm    Post subject: Sending binary data over WLAN Reply with quote

I am working on a full-featured web server in Lua, and I'm having trouble sending some binary files using the WLAN functions. Here's a portion of my code:

Code:
file = io.open(getloc, "rb")
            if file then
               incomingSocket:send("HTTP/1.0 200 OK\r\nContent-Type: " .. type .. "\r\n\r\n") -- Mime type was set earlier, for a PNG it will be image/png
               f_size = fileSize(file) -- Uses a fileSize function I declared
               graphicsPrint("File size is: " .. f_size .. "\n")
               graphicsPrint("Sending file")
               c_count = 0
               chunksize = 128
               bytes_read = 0
               while true do
                  bytes = file:read(chunksize)
                  if bytes ~= nil then
                     incomingSocket:send(bytes)
                  end
                     c_count = c_count + 1
                     graphicsPrint(".")
                     System.sleep(5)
                     bytes_read = bytes_read + chunksize
                     if bytes_read >= f_size then break end
               end
               graphicsPrint("\nSent a file with " .. c_count .. " chunks of " .. chunksize .. " bytes.\n")
               file:close()      
            end


I can successfully send a PNG file using this and it displays on my computer. However, JPG's are either not displaying at all or breaking halfway through.

Is this a bug in the WLAN functions, or is there some way for me to package my binary data so it stays intact when I send it? Thanks in advance.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Wed Dec 07, 2005 5:53 pm    Post subject: Re: Sending binary data over WLAN Reply with quote

The sockets are all in non-blocking mode and you have to check the result of send, how many bytes were actually sent and then use string.substr and a loop to send all.
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