| Reply | « Previous Thread | Next Thread » |
|
How can I detect if an internet connection is currently active on my phone?
And, once I see it is NOT active, how can I start it? |
|
Join Date: Feb 2008
Posts: 2,542
Location: Bhavnagar, Gujarat, India
gaba88
Offline
Forum Nokia Champion
|
|
|
Quote:
yes i think you can start a GPRS connection please have a look at this new wiki article. Hope this helps Enjoy Pythoning Gaba88 Gargi Das- http://gargidas.blogsot.com Forum Nokia Python Wiki Learn Python at http://mobapps.org/PyS60 |
|
thanks, cool link!
|
|
Join Date: Feb 2008
Posts: 2,542
Location: Bhavnagar, Gujarat, India
gaba88
Offline
Forum Nokia Champion
|
|
Hi cassioli
you are welcome the article was created by me yesterday only. I feel happy that it was helpful to you. Enjoy Pythoning Gaba88 Gargi Das- http://gargidas.blogsot.com Forum Nokia Python Wiki Learn Python at http://mobapps.org/PyS60 |
|
I did several tests, but I still cannot understand why&when my device raises the error "0, getaddrinfo failed" when I attempt to upload a file to a server:
Code:
# Copyright (c) 2007 Jurgen Scheible
# This script allows setting a default Access Point for connecting to the internet
# which omits the task of always manually selecting an Access Point each time when you
# open a Python script that connects to the internet.
# Note: you need at least PyS60 v.1.3.17
import appuifw,socket,urllib, e32
def unset_accesspoint():
f = open('e:\\apid.txt','w')
f.write(repr(None))
f.close()
appuifw.note(u"Default access point is unset ", "info")
def set_accesspoint():
apid = socket.select_access_point()
if appuifw.query(u"Set as default access point","query") == True:
f = open('e:\\apid.txt','w')
f.write(repr(apid))
f.close()
appuifw.note(u"Saved default access point ", "info")
apo = socket.access_point(apid)
socket.set_default_access_point(apo)
def download():
#---------------------- copy from here ---------------------------------------
try:
f=open('e:\\apid.txt','rb')
setting = f.read()
apid = eval(setting)
f.close()
if not apid == None :
apo = socket.access_point(apid)
socket.set_default_access_point(apo)
else:
set_accesspoint()
except:
set_accesspoint()
#------------------------- copy till here --------------------------------------
# and put it before the line of code in your script that invokes a connection to the internet
# like here with urllib.urlretrieve(url, tempfile)
# your own code here
print "Invio file..."
try:
sourcefile = 'e:\\fav.kml'
destfile = 'prova.txt'
print "Accedo a server FTP..."
ftp = FTP('ftp.altervista.org','user','pass') # connect to host
print "Cambio cartella..."
ftp.cwd('prove') # change directory where to store the file
print "Leggo file..."
F=open(sourcefile,'r')
print "Invio..."
ftp.storbinary('STOR ' + destfile,F,1024) # store the file
print "Inviato. Chiudo FTP..."
ftp.quit()
print "Chiudo file..."
F.close()
print "Finito!"
except Exception, e:
print "Impossibile inviare file:"
print str(e)
# url = "http://www.google.it"
# tempfile = 'e:\\Videos\\video.3gp'
# urllib.urlretrieve(url, tempfile)
# appuifw.note(u"Video downloaded" , "info")
def quit():
app_lock.signal()
appuifw.app.set_exit()
appuifw.app.menu = [(u"unset ap",unset_accesspoint),(u"download",download)]
#appuifw.app.exit_key_handler = quit
app_lock = e32.Ao_lock()
app_lock.wait()
![]() |
|
Quote:
The "0, getaddrinfo failed" occurs to me when using PED but the script runs well with the interpreter. Best Regards, Croozeus |
|
I tried with PUTOOLS PC-shell and with a script run by phone-shell.
|
|
Join Date: Feb 2008
Posts: 2,542
Location: Bhavnagar, Gujarat, India
gaba88
Offline
Forum Nokia Champion
|
|
hi cassioli
the error you are getting is a connection error may be there be a somekind of network problem. I used to get these kind of error due to bad network connection. Gargi Das- http://gargidas.blogsot.com Forum Nokia Python Wiki Learn Python at http://mobapps.org/PyS60 |
|
Quote:
Can you upload the file if you ignore the code for default access point ? Best Regards, Croozeus
Last edited by croozeus : 2008-08-24 at 16:05.
|
|
Quote:
- the only way to be able to get upload working is by manually selecting the access point - access_point().start() and .stop() do not affect at all actually active connections on phone: if no connections are active, .start() does not start a connection; if a connection is active, .stop() does not stop it. - if I try uploading a file without starting a connection before using .start(), I'm asked to select the connection to use, and once I choose it, the upload properly work (i.e. statement ftp = ftplib.FTP('ftp.altervista.org') does not raise any error ) |
|
Further tests with PUTOOLS (PC-shell):
f=ftplib.FTP('jumpjack.altervista.org') without active connections results in connectin selection dialog to appear; choosing CANCEL I get gaierror: (4, 'getaddrinfo failed') f=ftplib.FTP('jumpjack.altervista.org') without active connections results in connection-selection-dialog to appear; choosing WRONG connection (MMS rather than web) results in SUCCESSFULL (???) connection (message received from server) f=ftplib.FTP('jumpjack.altervista.org') without active connections results in connection-selection-dialog to appear; choosing INTERNET connection obviously results in successfull connection. f=ftplib.FTP('jumpjack.altervista.org') with activer connection generated by web browser results in connection-selection-dialog to appear (???). "CANCEL" results in error 4 (see above); selecting same APN used by browser results in: Traceback (most recent call last): File "<input>", line 1, in ? File "C:\system\libs\ftplib.py", line 79, in __init__ self.connect(host) File "C:\system\libs\ftplib.py", line 89, in connect self.sock.connect((self.host, self.port)) File "E:\system\libs\socket.py", line 316, in connect return self._sock.connect((gethostbyname(addr[0]), addr[1]), cb) error: (22, 'Invalid argument') What a mess... ![]() |
|
Hi cassioli,
is there any possibility to detect an active internet connection? Cheers, Willy |
| willy_backhaus |
| View Public Profile |
| Find all posts by willy_backhaus |
|
Quote:
![]() |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| nokia 6120 classic MIDP Internet Connection problem.. | dream_bolt | Mobile Java Networking & Messaging & Security | 3 | 2008-06-24 21:43 |
| Internet connection just aint disconnecting... | liormin | Mobile Java Networking & Messaging & Security | 1 | 2008-06-18 10:07 |
| RConnection::Start opens internet connection? | machiel | Wired and Wireless interfaces | 2 | 2008-05-26 16:46 |
| Is possible to create a new internet connection from J2ME? | Jordi Calella | Mobile Java General | 0 | 2005-04-27 12:23 |
| Connecting emulator to the Internet through computer's dial-up connection | mucky021 | Symbian Networking & Messaging | 1 | 2005-04-11 10:58 |