Code: Select all
white = Color.new(255, 255, 255)
offscreen = Image.createEmpty(480, 272)
offscreen:clear(Color.new(0, 0, 0))
y = 0
x = 0
function printstr( text )
local char = ""
for i = 1, string.len(text) do
char = string.sub(text, i, i)
if char == "\n" then
y = y + 8
x = 0
elseif char ~= "\r" then
offscreen:print(x, y, char, white)
x = x + 8
end
end
screen:blit(0, 0, offscreen)
screen.waitVblankStart()
screen.flip()
end
function println( text )
printstr(text .. "\n")
end
site = "www.luaplayer.org"
file = "wlan-test.txt"
host = "www.lua.org"
println("starting wlan...")
Wlan.init()
println("")
println("current configs:")
configs = Wlan.getConnectionConfigs()
for key, value in configs do
println(key .. ": " .. value)
end
println("")
println("using first connection...")
Wlan.useConnectionConfig(1)
println("")
println("resolving ip...")
while true do
ip = Wlan.getIPAddress()
if ip then break end
System.sleep(100)
end
println("psp ip: " .. ip)
println("")
println("connecting to: " .. site)
sock, error = Socket.connect(site, 80) -- ERROR HERE
println("")
println("waiting for connection... press start to abort")
abort = false
while not sock:isConnected() do
if Controls.read():start() then
abort = true
break
end
System.sleep(100)
end
if abort == false then
println("connected to " .. tostring(sock))
println("")
println("http connect as host: " .. host)
println("loading page... press start to abort")
sock:send("GET /" .. file .. " HTTP/1.0\r\n")
sock:send("host: " .. host .. "\r\n\r\n")
header = ""
while true do
buffer = sock:recv()
if string.len(buffer) > 0 then
header = header .. buffer
startIndex, endIndex = string.find(header, "\r\n\r\n")
if endIndex then
printstr(string.sub(header, endIndex))
break
end
end
if Controls.read():start() then
break
end
end
sock:close()
end
Wlan.term()
println("")
println("press start to exit")
while not Controls.read():start() do end