You Are Here:

Community: Developer Discussion Boards

#1 Old Detecting active internet connection - 2008-08-23, 23:42

Join Date: Mar 2003
Posts: 564
cassioli's Avatar
cassioli
Offline
Super Contributor
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?
Reply With Quote

#2 Old Re: Detecting active internet connection - 2008-08-24, 05:37

Join Date: Feb 2008
Posts: 2,542
Location: Bhavnagar, Gujarat, India
Send a message via Yahoo to gaba88 Send a message via Skype™ to gaba88
gaba88's Avatar
gaba88
Offline
Forum Nokia Champion
Quote:
Originally Posted by cassioli View Post
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?
hi cassioli
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
Reply With Quote

#3 Old Re: Detecting active internet connection - 2008-08-24, 12:58

Join Date: Mar 2003
Posts: 564
cassioli's Avatar
cassioli
Offline
Super Contributor
thanks, cool link!
Reply With Quote

#4 Old Re: Detecting active internet connection - 2008-08-24, 13:12

Join Date: Feb 2008
Posts: 2,542
Location: Bhavnagar, Gujarat, India
Send a message via Yahoo to gaba88 Send a message via Skype™ to gaba88
gaba88's Avatar
gaba88
Offline
Forum Nokia Champion
Quote:
Originally Posted by cassioli View Post
thanks, cool link!
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
Reply With Quote

#5 Old Re: Detecting active internet connection - 2008-08-24, 15:07

Join Date: Mar 2003
Posts: 564
cassioli's Avatar
cassioli
Offline
Super Contributor
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()
Only one time it worked, maybe when I manually selected the access point. I need an error-proof method to start a connection and to upload a file, can anybody help?!?
Reply With Quote

#6 Old Re: Detecting active internet connection - 2008-08-24, 15:11

Join Date: May 2007
Posts: 2,738
Location: 21.46 N 72.11 E
croozeus's Avatar
croozeus
Offline
Forum Nokia Champion
Quote:
Originally Posted by cassioli View Post
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:
Do you use the interpreter or PED to run the script ?

The "0, getaddrinfo failed" occurs to me when using PED but the script runs well with the interpreter.

Best Regards,
Croozeus
Reply With Quote

#7 Old Re: Detecting active internet connection - 2008-08-24, 15:45

Join Date: Mar 2003
Posts: 564
cassioli's Avatar
cassioli
Offline
Super Contributor
Quote:
Originally Posted by croozeus View Post
Do you use the interpreter or PED to run the script ?

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.
Reply With Quote

#8 Old Re: Detecting active internet connection - 2008-08-24, 15:52

Join Date: Feb 2008
Posts: 2,542
Location: Bhavnagar, Gujarat, India
Send a message via Yahoo to gaba88 Send a message via Skype™ to gaba88
gaba88's Avatar
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
Reply With Quote

#9 Old Re: Detecting active internet connection - 2008-08-24, 15:59

Join Date: May 2007
Posts: 2,738
Location: 21.46 N 72.11 E
croozeus's Avatar
croozeus
Offline
Forum Nokia Champion
Quote:
Originally Posted by cassioli View Post
I tried with PUTOOLS PC-shell and with a script run by phone-shell.

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.
Reply With Quote

#10 Old Re: Detecting active internet connection - 2008-08-24, 16:16

Join Date: Mar 2003
Posts: 564
cassioli's Avatar
cassioli
Offline
Super Contributor
Quote:
Originally Posted by croozeus View Post
Can you upload the file if you ignore the code for default access point ?

Best Regards,
Croozeus
I just finished doing other tests:
- 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 )
Reply With Quote

#11 Old Re: Detecting active internet connection - 2008-08-24, 16:27

Join Date: Mar 2003
Posts: 564
cassioli's Avatar
cassioli
Offline
Super Contributor
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...
Reply With Quote

#12 Old Re: Detecting active internet connection - 2008-12-01, 20:51

Join Date: Jul 2008
Posts: 6
willy_backhaus
Offline
Registered User
Hi cassioli,

is there any possibility to detect an active internet connection?

Cheers,
Willy



Quote:
Originally Posted by cassioli View Post
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?
Reply With Quote

#13 Old Re: Detecting active internet connection - 2008-12-02, 08:55

Join Date: Mar 2003
Posts: 564
cassioli's Avatar
cassioli
Offline
Super Contributor
Quote:
Originally Posted by willy_backhaus View Post
Hi cassioli,

is there any possibility to detect an active internet connection?

Cheers,
Willy
who knows?
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
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

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia