You Are Here:

Community: Developer Discussion Boards

#1 Old socket call problem - 2008-03-24, 10:09

Join Date: Jun 2003
Posts: 13
paravantinos
Offline
Registered User
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?
Reply With Quote

#2 Old Smile Re: socket call problem - 2008-03-25, 15:19

Join Date: Dec 2007
Posts: 134
Location: India
kandyfloss's Avatar
kandyfloss
Offline
Regular Contributor
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
Reply With Quote

#3 Old Re: socket call problem - 2008-03-25, 15:37

Join Date: Jun 2003
Posts: 13
paravantinos
Offline
Registered User
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?
Reply With Quote

#4 Old Re: socket call problem - 2008-03-25, 18:21

Join Date: Jun 2003
Posts: 13
paravantinos
Offline
Registered User
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?
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
Call Log Problem map123 General Symbian C++ 7 2007-03-07 17:08
Topic: Voice call status problem Need Help!!! hoy_cpe General Symbian C++ 3 2006-06-09 00:48
Hang up a call problem Bill_Murray General Symbian C++ 0 2006-04-01 10:35
Setup call problem bakakaba General Symbian C++ 2 2005-08-23 16:15
Problem in trying to connect to Incoming Call Rajagopalan General Symbian C++ 10 2004-09-10 06:29

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