You Are Here:

Community: Developer Discussion Boards

#1 Old close socket connetcion - 2009-03-12, 16:28

Join Date: Apr 2008
Posts: 24
impazzito
Offline
Registered User
Hi to all!

Can somebody help me?
I have created an application that connect to web, print value from a web page end then disconnect from the web (the disconnection don't work).
I have problem with socket.close() because don't work and i have to close my python app to close connection. Is there a way to close connection without close my app?

Thanks and sorry for my english!

Code:
import e32
import socket
from dialog import Wait, Progress
from fonts import*
t = e32.Ao_timer()
n = 0
credito = 0
m = 0


def ricevicredito():
 apid = 5
 ap = socket.access_point(apid)
 socket.set_default_access_point(ap)
 urlWEB = urllib.urlopen
 response = urlWEB('http://xxx').read()
 try:
  credito = re.search('<td class="xxx" width="">Il tuo credito residuo \xxxx', response).group(1)
 except:
  credito = 0.0
  n = credito
  print n
 e32.ao_sleep(0)
###############################
# CLOSE SOCKET CONNECTION     #
###############################
 socket.close()   #DON'T WORK
 t.after(5, ricevicredito)
Reply With Quote

#2 Old Re: close socket connetcion - 2009-03-12, 17:47

Join Date: Nov 2007
Posts: 317
Location: Sertaozinho/Brazil
Send a message via MSN to marcelobarrosalmeida Send a message via Skype™ to marcelobarrosalmeida
marcelobarrosalmeida's Avatar
marcelobarrosalmeida
Online
Forum Nokia Champion
Hi impazzito,

You only can close a socket objetct that you have created.
In this case, you did not create any socket object but you are calling the socket method "close".
So, just do nothing at the end, comment out the line socket.close()

In the following case you need an explicit close call:

Code:
from socket import *
s = socket(AF_INET,SOCK_STREAM)
s.connect((ip,port))
# communication goes here, s.send(), s.recv()
s.close()
BTW, these methods are static and dont need any object instantiated to call them:

Code:
socket.access_point(apid)
socket.set_default_access_point(ap)


Marcelo Barros
Nokia E71, N800, N95 and XM 5800
http://www.croozeus.com
http://wordmobi.wordpress.com
http://jedizone.wordpress.com
Reply With Quote

#3 Old Re: close socket connetcion - 2009-03-12, 20:40

Join Date: Apr 2008
Posts: 24
impazzito
Offline
Registered User
Thanks marcelobarrosalmeida!
I have solved!

Now I have another question.
Is there a way to "do something when a call is finisched"??

this is my idea:

Code:
make a call
close the conversation
start the programm
Reply With Quote

#4 Old Re: close socket connetcion - 2009-03-13, 01:22

Join Date: Nov 2007
Posts: 317
Location: Sertaozinho/Brazil
Send a message via MSN to marcelobarrosalmeida Send a message via Skype™ to marcelobarrosalmeida
marcelobarrosalmeida's Avatar
marcelobarrosalmeida
Online
Forum Nokia Champion
Quote:
Originally Posted by impazzito View Post
Thanks marcelobarrosalmeida!
I have solved!

Now I have another question.
Is there a way to "do something when a call is finisched"??

this is my idea:

Code:
make a call
close the conversation
start the programm
I think I didn't get the point. Sorry
If it is a different topic why not open a new thread ?
If it is related please try to explain again or put some code.

Marcelo


Marcelo Barros
Nokia E71, N800, N95 and XM 5800
http://www.croozeus.com
http://wordmobi.wordpress.com
http://jedizone.wordpress.com
Reply With Quote

#5 Old Re: close socket connetcion - 2009-03-17, 10:51

Join Date: Nov 2007
Posts: 4
madhacker
Offline
Registered User
Quote:
Originally Posted by impazzito View Post
Hi to all!

Can somebody help me?
I have created an application that connect to web, print value from a web page end then disconnect from the web (the disconnection don't work).
I have problem with socket.close() because don't work and i have to close my python app to close connection. Is there a way to close connection without close my app?

Thanks and sorry for my english!

Code:
import e32
import socket
from dialog import Wait, Progress
from fonts import*
t = e32.Ao_timer()
n = 0
credito = 0
m = 0


def ricevicredito():
 apid = 5
 ap = socket.access_point(apid)
 socket.set_default_access_point(ap)
 urlWEB = urllib.urlopen
 response = urlWEB('http://xxx').read()
 try:
  credito = re.search('<td class="xxx" width="">Il tuo credito residuo \xxxx', response).group(1)
 except:
  credito = 0.0
  n = credito
  print n
 e32.ao_sleep(0)
###############################
# CLOSE SOCKET CONNECTION     #
###############################
 socket.close()   #DON'T WORK
 t.after(5, ricevicredito)
try this
Code:
import e32
import socket
from dialog import Wait, Progress
from fonts import*
t = e32.Ao_timer()
n = 0
credito = 0
m = 0


def ricevicredito():
 apid = 5
 ap = socket.access_point(apid)
 socket.set_default_access_point(ap)
 urlWEB = urllib.urlopen
 response = urlWEB('http://xxx').read()
 try:
  credito = re.search('<td class="xxx" width="">Il tuo credito residuo \xxxx', response).group(1)
 except:
  credito = 0.0
  n = credito
  print n
 e32.ao_sleep(0)
###############################
# CLOSE SOCKET CONNECTION     #
###############################
 socket.close()   #DON'T WORK
 ap.stop() #THIS STOP CONNECTION
 t.after(5, ricevicredito)
bye
Reply With Quote

#6 Old Re: close socket connetcion - 2009-03-17, 16:00

Join Date: Nov 2007
Posts: 317
Location: Sertaozinho/Brazil
Send a message via MSN to marcelobarrosalmeida Send a message via Skype™ to marcelobarrosalmeida
marcelobarrosalmeida's Avatar
marcelobarrosalmeida
Online
Forum Nokia Champion
So, madhacker, this is the same code you put in previous posts, even with same problems (socket.close(), for instance). If you want to open an url and get a result, you may try:

Code:
import urllib
 
# returns a file like interface
furl = urllib.urlopen("http://your_url_goes_here")
# reading the "file"
contents = furl.read()
# saving the page contents
flocal = open("filename_here.html","wt")
flocal.write(contents)
or

Code:
import urllib
urllib.urlretrieve("http://your_url_goes_here","filename_here.html")


Marcelo Barros
Nokia E71, N800, N95 and XM 5800
http://www.croozeus.com
http://wordmobi.wordpress.com
http://jedizone.wordpress.com
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
problem in persistant socket connection poms4symbian Browsing and Mark-ups 0 2006-01-03 14:23
Explicitly close socket connection phibo Mobile Java Networking & Messaging & Security 1 2005-11-25 16:15
Socket problem defragger Python 0 2005-08-25 09:16
Symbian socket close bug? matdodgson Symbian Networking & Messaging 2 2004-03-26 14:35
close and reconenct of socket cs_lcmaa Symbian Networking & Messaging 2 2003-11-13 04:31

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