[Pythonmac-SIG] Lost connection
bob ackerman
rdacker@pacbell.net
Sun, 28 Apr 2002 11:23:50 -0700
--Boundary_(ID_2bmEYc/Q91pBu1Upm+37Sw)
Content-type: text/plain; charset=US-ASCII; format=flowed
Content-transfer-encoding: 7BIT
On Saturday, April 27, 2002, at 09:53 PM, broz wrote:
> Hi folks,
>
> The solution to my problem could very well seem obvious, but to me it's
> not
> obvious.
>
> I've got a python application that opens a socket, receives data (XML),
> parses it, and updates a database. Under normal circumstances, it all
> works
> just fine. Under abnormal circumstances, it sits and spins.
>
> The main application opens a socket with listen(), and then accept() is
> called. It dutifully waits for the other machine to connect() and start
> dumping data. That process works fine. If the other machine drops the
> line,
> things get hairy. My python app thinks the connection is still live, and
> spins waiting for more data. I'm just doing a socket.recv(2048) to get the
> data. I would have expected an error to be thrown if the connection
> failed,
> but no error is thrown.
i don't think you should be doing a listen in socketSetup.
i don't think that would cause your problem, but it might help to take it
out.
> Odd.
>
> What I need to do is discover the connection went down, and open a new one
> when the server on the other end comes back.
>
> I'm running this on Mac OS X. How can I tell the connection went down?
>
> Thanks in advance.
>
>
> def socketSetup(self, thePort):
>
> try:
> self.theSock = socket(AF_INET, SOCK_STREAM)
>
> self.theSock.bind(('', thePort))
> self.theSock.listen(5)
> except Exception, theErr:
> self.logger.logStatus( "connection failed: " + str(theErr))
>
> def socketConnect(self):
> " this is where we accept the connection from the server"
> print "in socketConnect"
> try:
> if not self.theSock:
> print "theSock is None!"
> else:
> self.theConnection, theAddress = self.theSock.accept()
> self.connected = 1
>
> except socket.error, theErr:
> self.connected = 0
> print "socketConnect error - " + str(error) + ": " +
> str(theErr)
>
> def getConnectStatus(self):
> return self.connected
>
> def getData(self):
> "handle data feeds from either a file or a socket"
> # print "getData called"
> try:
> if self.connected:
>
> self.theData = self.theConnection.recv(2048)
> else:
> self.socketConnect()
>
> return self.theData
> except Exception, theErr:
> print ("getData error: " + theErr)
> self.logger.log("getData error: " + theErr)
>
>
>
> --
>
> Richard Brosnahan
> Editor in Chief
> Broz News
> Hand Picked Technical News
> Updated Every Business Day!
> http://broznews.com/
>
>
>
>
> _______________________________________________
> Pythonmac-SIG maillist - Pythonmac-SIG@python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig
>
--Boundary_(ID_2bmEYc/Q91pBu1Upm+37Sw)
Content-type: text/enriched; charset=US-ASCII
Content-transfer-encoding: 7BIT
On Saturday, April 27, 2002, at 09:53 PM, broz wrote:
<excerpt>Hi folks,
The solution to my problem could very well seem obvious, but to me
it's not
obvious.
I've got a python application that opens a socket, receives data (XML),
parses it, and updates a database. Under normal circumstances, it all
works
just fine. Under abnormal circumstances, it sits and spins.
The main application opens a socket with listen(), and then accept() is
called. It dutifully waits for the other machine to connect() and start
dumping data. That process works fine. If the other machine drops the
line,
things get hairy. My python app thinks the connection is still live,
and
spins waiting for more data. I'm just doing a socket.recv(2048) to get
the
data. I would have expected an error to be thrown if the connection
failed,
but no error is thrown.
</excerpt>
i don't think you should be doing a listen in
<color><param>0000,0000,DEDE</param>socketSetup</color>.
i don't think that would cause your problem, but it might help to take
it out.
<excerpt>Odd.
What I need to do is discover the connection went down, and open a new
one
when the server on the other end comes back.
I'm running this on Mac OS X. How can I tell the connection went down?
Thanks in advance.
def socketSetup(self, thePort):
try:
self.theSock = socket(AF_INET, SOCK_STREAM)
self.theSock.bind(('', thePort))
self.theSock.listen(5)
except Exception, theErr:
self.logger.logStatus( "connection failed: " + str(theErr))
def socketConnect(self):
" this is where we accept the connection from the server"
print "in socketConnect"
try:
if not self.theSock:
print "theSock is None!"
else:
self.theConnection, theAddress = self.theSock.accept()
self.connected = 1
except socket.error, theErr:
self.connected = 0
print "socketConnect error - " + str(error) + ": " +
str(theErr)
def getConnectStatus(self):
return self.connected
def getData(self):
"handle data feeds from either a file or a socket"
# print "getData called"
try:
if self.connected:
self.theData = self.theConnection.recv(2048)
else:
self.socketConnect()
return self.theData
except Exception, theErr:
print ("getData error: " + theErr)
self.logger.log("getData error: " + theErr)
--
Richard Brosnahan
Editor in Chief
Broz News
Hand Picked Technical News
Updated Every Business Day!
http://broznews.com/
_______________________________________________
Pythonmac-SIG maillist - Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig
</excerpt>
--Boundary_(ID_2bmEYc/Q91pBu1Upm+37Sw)--