You Are Here:

Community: Developer Discussion Boards

#1 Old timeout on the socket - 2009-01-28, 15:49

Join Date: Nov 2008
Posts: 139
widetech1
Offline
Regular Contributor
hi friends

how to make a timeout on the socket to avoid being hung in the send () and the recv ()?

thanks
Reply With Quote

#2 Old Re: timeout on the socket - 2009-01-28, 20:28

Join Date: Nov 2007
Posts: 318
Location: Sertaozinho/Brazil
Send a message via MSN to marcelobarrosalmeida Send a message via Skype™ to marcelobarrosalmeida
marcelobarrosalmeida's Avatar
marcelobarrosalmeida
Offline
Forum Nokia Champion
Quote:
Originally Posted by widetech1 View Post
hi friends

how to make a timeout on the socket to avoid being hung in the send () and the recv ()?

thanks
Socket object has settimeout() member function. Just put your timeout when calling. Again, python 1.9.x only.

Code:
from socket import *
s = socket(AF_INET, SOCK_STREAM)
s.settimeout(1.5) # one second and a half
Any operation using this socket will raise an exception if the timeout is reached.

Bye

Still recommending "Foundations of Python Network Programming".
Many insights inside ! :-D


Marcelo Barros
Nokia E71, N800, N95 and XM 5800
http://www.croozeus.com
http://wordmobi.wordpress.com
http://jedizone.wordpress.com
Last edited by marcelobarrosalmeida : 2009-02-05 at 12:30.
Reply With Quote

#3 Old Re: timeout on the socket - 2009-01-29, 06:52

Join Date: Jan 2009
Posts: 64
Location: India
Send a message via AIM to pavan.pareta Send a message via MSN to pavan.pareta Send a message via Yahoo to pavan.pareta Send a message via Skype™ to pavan.pareta
pavan.pareta's Avatar
pavan.pareta
Offline
Regular Contributor
Quote:
Originally Posted by widetech1 View Post
hi friends

how to make a timeout on the socket to avoid being hung in the send () and the recv ()?

thanks
See the below example this is also handling exception for time out.



Quote:
def get_request(self):
while self.run:
try:
sock, addr = self.socket.accept()
sock.settimeout(2)
return (sock, addr)
except socket.timeout:
pass

Hope that this may be help


Pavan Pareta

http://www.croozeus.com/started.htm
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
[announce] tsocket: socket module + timeout on connect lfd Python 6 2007-06-10 14:05
How to get the default timeout time of the socket which use RFCOMM protocol? rensijie Symbian Networking & Messaging 0 2006-08-22 11:41
How to get the default timeout time of the socket which use RFCOMM protocol?? rensijie General Symbian C++ 0 2006-08-22 11:39
problem in persistant socket connection poms4symbian Browsing and Mark-ups 0 2006-01-03 14:23
TCP Socket default timeout barre30 Mobile Java Networking & Messaging & Security 0 2004-08-06 12:30

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