| View previous topic :: View next topic |
| Author |
Message |
erifash

Joined: 28 Nov 2005 Posts: 6
|
Posted: Sun Mar 26, 2006 5:33 pm Post subject: Socket.connect() not working |
|
|
I am having a problem with a wlan-test program I modified. When it executes Socket.connect() the wlan light is on but not blinking, and it just stays that way (maybe frozen, I don't know). Can anyone look at the code and find out if this is a simple coding error or something wrong with my psp?
| Code: | 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 |
Thanks for your time! _________________ AutoIt3 scripter. |
|
| Back to top |
|
 |
erifash

Joined: 28 Nov 2005 Posts: 6
|
Posted: Mon Mar 27, 2006 11:52 pm Post subject: |
|
|
Okay, I tested my wifi connection under network settings and everything checks out okay. So it is not a problem with my psp's wifi or, if anyone tells me otherwise, my code. It must be something corrupted in luaplayer... I will download it again and see if that doesn't fix it. _________________ AutoIt3 scripter. |
|
| Back to top |
|
 |
erifash

Joined: 28 Nov 2005 Posts: 6
|
Posted: Tue Mar 28, 2006 12:36 am Post subject: |
|
|
This is messed up... Earlier (before I last posted) I modified the script and it got past the connection freeze, but it wouldn't resolve www.luaplayer.org's correct ip address and kept on giving me an error page. Now, even when I use the above code it freezes up when it says "using first connection..." The wlan light stays solid for two seconds then the light turns off. Can anyone please help me with this problem? _________________ AutoIt3 scripter. |
|
| Back to top |
|
 |
be2003
Joined: 20 Apr 2006 Posts: 144
|
Posted: Thu Apr 20, 2006 4:11 pm Post subject: lol...site mix up |
|
|
| Code: | | host = "www.luaplayer.org" | not lua.org, you are mixing up sites _________________ - be2003
blog |
|
| Back to top |
|
 |
aserto
Joined: 17 Apr 2006 Posts: 22
|
Posted: Fri May 12, 2006 11:18 pm Post subject: |
|
|
I have a similar problem. I can't use sockets in my apps. If I use them the program freezes at the instruction
| Code: | | Wlan.useConnectionConfig(1) |
i use eloader 0.97, luaplayer 0.16, firmware 2.60
what's the problem? |
|
| Back to top |
|
 |
aserto
Joined: 17 Apr 2006 Posts: 22
|
Posted: Tue May 16, 2006 11:48 pm Post subject: |
|
|
i found the problem... eloader 0.97 with luaplayer needs a dhcp connection.
But now i have another problem with wifi:
when i do
| Code: |
socket, error = Socket.connect(host, port)
while not socket:isConnected() do System.sleep(100) end
|
the program seems to fall in an infinite loop.
What could i do? |
|
| Back to top |
|
 |
Altair
Joined: 20 May 2006 Posts: 76 Location: The Netherlands
|
Posted: Sat May 20, 2006 2:37 am Post subject: |
|
|
| erifash wrote: | | This is messed up... Earlier (before I last posted) I modified the script and it got past the connection freeze, but it wouldn't resolve www.luaplayer.org's correct ip address and kept on giving me an error page. Now, even when I use the above code it freezes up when it says "using first connection..." The wlan light stays solid for two seconds then the light turns off. Can anyone please help me with this problem? |
Same thing happens to me. The program freezes, but the home-button etc. still work. I guess this means it isn't necesairely my fault? Or are we doing something wrong. BTW I use 0.16 and have firmware 1.5. |
|
| Back to top |
|
 |
romero126
Joined: 24 Dec 2005 Posts: 200
|
Posted: Sat May 20, 2006 5:23 am Post subject: |
|
|
| 0.16 has no DNS you will have to type the ipaddress manual. Example. 192.168.1.1 |
|
| Back to top |
|
 |
Altair
Joined: 20 May 2006 Posts: 76 Location: The Netherlands
|
Posted: Sat May 20, 2006 7:17 am Post subject: |
|
|
aaaah thanks alot. Ill try that.
BTW you use 192.168.1.1 as an example. Maybe a very stupid question, but that's for a LAN or am i wrong? So does that mean i should connect like that to my router or something and then make it go for a page or whatever? |
|
| Back to top |
|
 |
aserto
Joined: 17 Apr 2006 Posts: 22
|
Posted: Sat May 20, 2006 7:18 pm Post subject: |
|
|
| Quote: |
0.16 has no DNS you will have to type the ipaddress manual. Example. 192.168.1.1
|
From Luaplayer changelog:
| Quote: |
v0.16 (all changes for this version by Shine)
================================================
- Wlan:getIPAddress bugfix: now it returns nil on error and the
IP address otherwise
- DNS resolving. Now you can write
Socket.connect("www.luaplayer.org", 80) instead of
Socket.connect("212.227.39.202", 80),
thanks to ideas how to use the resolver lib from PSPRadio
- when loading JPEGs, the file was not closed
- System.md5sum bugfixing for the Windows version
- Wlan.useConnectionConfig index is 1 based instead of 0 based, like usual in Lua
- System.powerTick added: this prevents power off, now you can nail
your PSP on a wall for your electronic painting :-)
- System.createDirectory, System.removeDirectory and System.removeFile added
|
maybe you missed DNS in wlan configuration... |
|
| Back to top |
|
 |
Altair
Joined: 20 May 2006 Posts: 76 Location: The Netherlands
|
Posted: Sat May 20, 2006 10:01 pm Post subject: |
|
|
| aserto wrote: | | maybe you missed DNS in wlan configuration... |
What exactly do you mean by that? Can I change something with regards to DNS or anything? |
|
| Back to top |
|
 |
aserto
Joined: 17 Apr 2006 Posts: 22
|
Posted: Sat May 20, 2006 10:31 pm Post subject: |
|
|
| i mean in the connection configuration the DNS server field |
|
| Back to top |
|
 |
Altair
Joined: 20 May 2006 Posts: 76 Location: The Netherlands
|
Posted: Sat May 20, 2006 11:58 pm Post subject: |
|
|
I guess i just don't know enough about this.
Maybe you could help me with this? I used parts from the wlan example in LUA-player.
This is what i have. First it asks for a name for the session. Then it asks you to choose the connection. This all works, but when i choose one, the wlan light stays on for 2 seconds and then it freezes, like said before.
| Code: | wit=Color.new(255, 255, 255)
wy=1
endinput=false
dofile("OSK.lua")
function name()
while true do
screen:clear()
screen:print(0,0,"Enter a name for your game.",wit)
pad = Controls.read()
oldpad=pad
if pad:circle() then
ready=false
while true do
screen:clear()
new_message()
read_osk_controls()
screen.waitVblankStart()
screen.flip()
if ready==true then
break
end
end
end
if pad:cross() then
if text~="" then
connect=true
break
end
if text=="" then
screen:print(175,132,"error: no name!",wit)
end
end
if pad:start() then
connect=false
break
end
if text~="" then
id=text
screen:print(0,8,"Game name:"..id,wit)
end
screen:print(0,264,"Press X to continue. Press O to enter a name.",wit)
screen.waitVblankStart()
screen.flip()
end
end
--------------------------------------------------------------------------
function connection()
Wlan.init()
configs = Wlan.getConnectionConfigs()
while true do
screen:clear()
l=8
screen:print(10,0,"Available connections:",wit)
for key, value in configs do
screen:print(10,l,key .. ": " .. value,wit)
l=l+8
end
pad = Controls.read()
if pad ~= oldpad then
if pad:up() then
if wy>1 then
wy=wy-1
elseif wy==1 then
wy=(l/8-1)
end
end
if pad:down() then
if wy<(l/8-1) then
wy=wy+1
elseif wy==(l/8-1) then
wy=1
end
end
if pad:cross() then
connect=true
break
end
if pad:start() then
connect=false
-- break
end
end
oldpad=pad
screen:print(0,wy*8-1,"o",wit)
screen:print(350,0,"wy="..wy,wit)
if connect==true then
screen:print(350,8,"connect=true",wit)
end
screen:print(350,16,"l="..l,wit)
screen:print(0,264,"Press X to select. Press start to cancel.",wit)
screen.waitVblankStart()
screen.flip()
end
end
--------------------------------------------------------------------------
function connecting()
Wlan.useConnectionConfig(wy)
-- start server socket (niet nodig denk ik?)
screen:print(0,l,"opening server socket...",wit)
screen.waitVblankStart()
screen.flip()
serverSocket = Socket.createServerSocket(80)
-- start connection and wait until it is connected
screen:print(0,l,"waiting for WLAN init and determining IP address...",wit)
screen.waitVblankStart()
screen.flip()
while true do
ipAddress = Wlan.getIPAddress()
if ipAddress then break end
System.sleep(100)
end
screen:print(0,l,"the PSP IP address is: " .. ipAddress,wit)
screen:print(0,l,"connecting to 208.97.136.133:80...",wit)
screen.waitVblankStart()
screen.flip()
socket, error = Socket.connect("208.97.136.133", 80)
while not socket:isConnected() do System.sleep(100) end
screen:print(0,l,"connected to " .. tostring(socket),wit)
screen.waitVblankStart()
screen.flip()
end
--------------------------------------------------------------------------
name()
if connect==true then
connection()
end
if connect==true then
connecting()
end |
|
|
| Back to top |
|
 |
aserto
Joined: 17 Apr 2006 Posts: 22
|
Posted: Sun May 21, 2006 7:22 pm Post subject: |
|
|
| if you have a 2.0+ firmware and you are using eloader 0.97 you need to make a dhcp connection. Try... |
|
| Back to top |
|
 |
Altair
Joined: 20 May 2006 Posts: 76 Location: The Netherlands
|
Posted: Sun May 21, 2006 8:45 pm Post subject: |
|
|
| I have 1.5, but how can you make a dhcp connection with LUA? |
|
| Back to top |
|
 |
aserto
Joined: 17 Apr 2006 Posts: 22
|
Posted: Sun May 21, 2006 9:04 pm Post subject: |
|
|
| You have to do it in the network settings |
|
| Back to top |
|
 |
Altair
Joined: 20 May 2006 Posts: 76 Location: The Netherlands
|
Posted: Tue May 23, 2006 6:19 am Post subject: |
|
|
| Do you mean setting everything to automatic? |
|
| Back to top |
|
 |
Altair
Joined: 20 May 2006 Posts: 76 Location: The Netherlands
|
Posted: Thu May 25, 2006 4:40 am Post subject: |
|
|
Still haven't figured this out. I just wanted to add this:
If I select a connection and tell it to connect, it doesn't even show "opening server socket...". So I think this means "Wlan.useConnectionConfig(wy)" isn't working. Or atleast I dont get it to work...
Also in the wiki it says to use "Socket:createServerSocket(port)" and not "Socket.createServerSocket(port)" (one is with a colon and one with a dot). While the example of the Wlan uses the one with the dot. So which one is it? |
|
| Back to top |
|
 |
Altair
Joined: 20 May 2006 Posts: 76 Location: The Netherlands
|
Posted: Mon May 29, 2006 12:26 am Post subject: |
|
|
| Got it! I had to manually type in another IP adress for my PSP. |
|
| Back to top |
|
 |
|