473,394 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Minimizing Connection reset by peer exceptions

This may be more of a socket question than a python question; not sure.

Using this code to instantiate/connect/set options
connectionHandle = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
errorStatus = connectionHandle.connect_ex((ipAddress, port))
connectionHandle.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO,
60000)

Using this code to send:
retSendAll = connectionHandle.sendall(messageToHost)

Followed by this code to recv:
bufferSize = 500000
responseBuffer = connectionHandle.recv(bufferSize)

Occasionally (perhaps 5% of the time) the following exception gets
raised:

(10054, 'Connection reset by peer')
Are there any changes I can make to the code above to eliminate the
10054 errors or to reduce the probability of encountering the 10054
error? Are there any settings that make the 'Connection reset by
peer' condition less likely?

Other posts on this subject seem to suggest that this can only be
handled by:
1) detecting the 10054 error
2) issuing a message explaining the 'connection reset' condition
followed by something along the lines of 'try again later'.

Oct 20 '05 #1
3 14090

mi************@yahoo.com wrote:
Occasionally (perhaps 5% of the time) the following exception gets
raised:

(10054, 'Connection reset by peer')


Generally this just means the connection has closed through some
unusual means, perhaps by being turned off, or a network cable being
unplugged, or a timeout along the way, etc. 5% is a high figure, but
perhaps you connect to hosts that are unreliable for some reason.

You don't have control over this really; just make sure you handle the
exception. Such is life, when dealing with networking.

--
Ben Sizer

Oct 20 '05 #2
Ben Sizer wrote:
mi************@yahoo.com wrote:

Occasionally (perhaps 5% of the time) the following exception gets
raised:

(10054, 'Connection reset by peer')

Generally this just means the connection has closed through some
unusual means, perhaps by being turned off, or a network cable being
unplugged, or a timeout along the way, etc. 5% is a high figure, but
perhaps you connect to hosts that are unreliable for some reason.

You don't have control over this really; just make sure you handle the
exception. Such is life, when dealing with networking.

Do note, though, that if you aren't using some means (threading,
forking, etc) of handling the connections asynchronously then your
server will normally only queue a very limited number of connections
(usually 5 at most).

So if your service takes a while to run then it's possible that
connection requests will be rejected when the queue is full, which might
*possibly* result in the error you are seeing.

Feel free to ignore this if you only have one client at a time.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Oct 20 '05 #3

Steve Holden wrote:
Do note, though, that if you aren't using some means (threading,
forking, etc) of handling the connections asynchronously then your
server will normally only queue a very limited number of connections
(usually 5 at most).


The example given by the original poster seemed to be a client (using
connect_ex) rather than a server, so I think this would only be an
issue if the code was connecting to the same host repeatedly in quick
succession.

--
Ben Sizer

Oct 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Donnal Walter | last post by:
On Windows XP I am able to connect to a remote telnet server from the command prompt using: telnet nnn.nnn.nnn.nnn 23 where nnn.nnn.nnn.nnn is the IP address of the host. But using telnetlib,...
1
by: Bernd | last post by:
Hello, i have a problem with my network code. What i want to do is, send an UDP-packet and check if i get an icmp-reply type 3 (dest. unreachable). the code looks like that so far: .. ..
4
by: Joe Lester | last post by:
I'm seeing this message a couple times per day in my postgres log: 2004-04-20 14:47:46 LOG: could not receive data from client: Connection reset by peer What does it mean? I've seen in the...
3
by: Van_Gogh | last post by:
Hi, I am learning how to use the smtplib module, but am having some very early problems, maybe because I don't understand it. So, am I correct that by following the example in the Python: >>>...
14
by: ahlongxp | last post by:
Hi, everyone, I'm implementing a simple client/server protocol. Now I've got a situation: client will send server command,header paires and optionally body. server checks headers and decides...
5
by: chrispoliquin | last post by:
Hi, I have a small Python script to fetch some pages from the internet. There are a lot of pages and I am looping through them and then downloading the page using urlretrieve() in the urllib...
0
by: fscali | last post by:
Hi, we are using a client c# console application to test a web service which uses Easy Soap. We are currently stuck in a strange problem which occurs only in a particular method call to the web...
0
by: jhaski | last post by:
I made a python program that crawls a major website and collects a bunch of data. I have found that I get "connection reset by peer" issues on almost every page I crawl. I keep a log of every page,...
2
by: gigs | last post by:
I connect to web site with httplib.HTTPConnection. after some time i get this error: 104 "connection reset by peer". What exception i should use to catche this error thx!
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.