×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    13

    socket call problem

    I'm developing an application that connects to the internet to upload some data.
    I try to avoid the annoying popup of apn selection everytime a connection is needed, so I use the following function:
    Code:
    def select_apn():
    	global apo, apid
    	apid = socket.select_access_point()
    	apo = socket.access_point(apid)
    	socket.set_default_access_point(apo)
    and then in my code, i use something like this:

    Code:
    if appuifw.query(u"Game Over. Score:"+str(score)+u" Upload online?", "query") == True:
               global apo
               if apo == None:select_apn()
               name = checkuserid()
               try:
                    params = urllib.urlencode({'Name': name, 'Score': score})
                    f = urllib.urlopen("http://xxxxx", params)
                    result=f.read()
                    if result.find("Success")>0:
                        appuifw.note(u"Score was submitted succesfully!", "info")
                    else:
                        if appuifw.note(u"Database Error! Try again?", "query")==True:tryagain=1
               except:
                    if appuifw.note(u"No valid network found!", "query")==True:tryagain=1
    	   apo.stop()
    The problem is that, after the default access point selection, the code quits, no error messages, just quits.

    Any ideas?

  2. #2
    Regular Contributor
    Join Date
    Dec 2007
    Location
    India
    Posts
    133

    Smile Re: socket call problem

    Hi,

    I would suggest you to use the following code for setting and unsetting the default access points. You can add your upload statements to this script after the set_accesspoint function call and see if it works.

    Code:
    import appuifw,socket,urllib
    
    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
        url = "http://www.leninsgodson.com/courses/pys60/resources/vid001.3gp"
        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()
    Hope it helps
    Kandyfloss

    V 7.0642.0
    18-10-06
    RH-51
    Nokia 7610

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    13

    Re: socket call problem

    Hi Kandyfloss and thanks for the reply!

    When I run your code as it is, it works perfectly,

    But when I try to integrate it within my application, the same behaviour pops up. It crashes after apn selection.

    I suspect that it has something to do with canvas callbacks etc, as I use canvas for the application UI. I'm new to Symbian development, I don't understand well the terms threading, ao, callbacks etc

    Do you believe that the problem has to do with canvas interaction with socket?

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    13

    Re: socket call problem

    Ok, i found it...

    The application uses sensor, and for some reason I had to disconnect sensor before calling socket. Now it works!

    Could someone explain me why that happened?

Similar Threads

  1. Call Log Problem
    By map123 in forum Symbian
    Replies: 7
    Last Post: 2007-03-07, 16:08
  2. Topic: Voice call status problem Need Help!!!
    By hoy_cpe in forum Symbian
    Replies: 3
    Last Post: 2006-06-08, 23:48
  3. Hang up a call problem
    By Bill_Murray in forum Symbian
    Replies: 0
    Last Post: 2006-04-01, 09:35
  4. Setup call problem
    By bakakaba in forum Symbian
    Replies: 2
    Last Post: 2005-08-23, 15:15
  5. Problem in trying to connect to Incoming Call
    By Rajagopalan in forum Symbian
    Replies: 10
    Last Post: 2004-09-10, 05:29

Posting Permissions

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