socket freezes

L

Luis P. Mendes

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I've developed a program that uses a socket to receive information 24h a
~ day.

The problem is that the socket seems to freeze. By that I mean the
program stops getting information but doesn't raise any error.

I tried to solve this by writing the following functions, in order to
try to start the socket connection again:

def keepAlive(self):
~ self.alive = 0
~ tnow = time.time()
~ if tnow - self.lastTime > 90: # last time got from last string
received from the socket
~ self.alive = 1

def reSocket():
~ print "socket has failed", time.strftime('%X', time.localtime())
~ time.sleep(60)
~ l=GServer() # new instance that contains the socket

reSocket is triggered when self.alive is 1.

But it hasn't solved my problem. These functions have effect only after
I do a ^C, and even then, the socket doesn't start to acquire new input.

Any clues you can give me about this?


Luis P. Mendes


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFECEF8Hn4UHCY8rB8RAtaaAKCnFb2O28AE4uRTK0sPSpnOifaDzACdG2EA
imVqvzcRX4qGWqMzLRUcyao=
=Cqkb
-----END PGP SIGNATURE-----
 
R

Rene Pijlman

Luis P. Mendes:
I've developed a program that uses a socket to receive information 24h a
~ day.

The problem is that the socket seems to freeze. By that I mean the
program stops getting information but doesn't raise any error.

That's weird. There's probably a bug in your program.
I tried to solve this by writing the following functions, in order to
try to start the socket connection again:

So now you have two problems. When there's a bug in your program, it's
usually best to hunt it down, rather than to add more code with more bugs
:)
 
S

Steve Holden

Luis said:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I've developed a program that uses a socket to receive information 24h a
~ day.

The problem is that the socket seems to freeze. By that I mean the
program stops getting information but doesn't raise any error.

I tried to solve this by writing the following functions, in order to
try to start the socket connection again:

def keepAlive(self):
~ self.alive = 0
~ tnow = time.time()
~ if tnow - self.lastTime > 90: # last time got from last string
received from the socket
~ self.alive = 1

def reSocket():
~ print "socket has failed", time.strftime('%X', time.localtime())
~ time.sleep(60)
~ l=GServer() # new instance that contains the socket

reSocket is triggered when self.alive is 1.

But it hasn't solved my problem. These functions have effect only after
I do a ^C, and even then, the socket doesn't start to acquire new input.

Any clues you can give me about this?
Try setting a default timeout on the socket, and if it times out
recontact the other system on a new socket. See socket.setdefaultimeout()

regards
Steve
 
L

Luis P. Mendes

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


| Try setting a default timeout on the socket, and if it times out
| recontact the other system on a new socket. See socket.setdefaultimeout()
|
| regards
| Steve

Thank you for your answers.

I'm beggining to suspect that the problem has to do with a discontinual
of service of the ISP. It provides me a dynamic IP address not a static
one.

I say this because after some hours, I returned to the computer and
could not acess the internet for surfing port 80 and the socket was also
down again - it just uses another port.

After unplugging the power cord of the cable modem from the internet and
pluging it in after a while, I could already access sites (http). But
the socket was still down, still with no error raised.

Based on this hypothesis, is there any way for my python program to deal
with this? Any thoughts?

Thanks again.

Luis
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFECKMmHn4UHCY8rB8RAoeAAJ92sEUsFk2bsXcCX77cDyHY2jOogwCgnGKZ
xStEmoEDTDrhVE7+aIAxSbI=
=qzed
-----END PGP SIGNATURE-----
 
J

jordan.taylor2

Might want to check out the SO_REUSEADDR bit in sockets. I believe it
helps with a problem of a program not notifying the OS that it's done
with the port.
Piece of a script (duh):

host = ""
port = 51423 #random for this example

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host, port))

Good Luck :D
 
D

Dennis Lee Bieber

I'm beggining to suspect that the problem has to do with a discontinual
of service of the ISP. It provides me a dynamic IP address not a static
one.
And many ISPs force a "lease renewal" after some period of time
(hours or days).
I say this because after some hours, I returned to the computer and
could not acess the internet for surfing port 80 and the socket was also
down again - it just uses another port.

After unplugging the power cord of the cable modem from the internet and
pluging it in after a while, I could already access sites (http). But
the socket was still down, still with no error raised.
Well, HTTP is you making a NEW socket connection on each page
request -- port 80 is the port number the other end is listening on. And
those close when the page is rendered.

But if you have a program that had an open socket connection to some
other host, after the lease renewal your IP # has changed, so the socket
that was created on IP1:portN (which the other end is trying to talk to)
is no longer a valid link. You basically have to take down the socket,
and recreate it with the new IP...
--
 
S

Steve Holden

Dennis said:
And many ISPs force a "lease renewal" after some period of time
(hours or days).
The DHCP protocol is supposed to allow lease renewal throughout the
lease period, and clients are normally expected to renew their lease
halfway through the lease period. So a continuously-connected system
should retain the same IP address.

If ISPs are *forcing* lease renewal they are perverting DHCP. Network
service should be continuous as long as a system remains continuously
connected.

regards
Steve
 
L

Luis P. Mendes

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thank you all for your suggestions.



Luis P. Mendes
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFECb5AHn4UHCY8rB8RAmeLAKCmSVfTvgQ94NPnJlD2QqdbMwVFXACdGFAh
8GL/9zxwXCYcmWxpyDweggE=
=9U0o
-----END PGP SIGNATURE-----
 
D

Dennis Lee Bieber

The DHCP protocol is supposed to allow lease renewal throughout the
lease period, and clients are normally expected to renew their lease
halfway through the lease period. So a continuously-connected system
should retain the same IP address.

If ISPs are *forcing* lease renewal they are perverting DHCP. Network
service should be continuous as long as a system remains continuously
connected.

I'll have to confess I've not tracked my IP currently... I do know
that my prior dial-up service used to do a drop at something like
24hours 1 minute from time of initial connect. Later it was a forced
drop at roughly 20minutes after midnight.

Since my DSL service is PPPoE, it may disconnect during idle periods
(in the old days, I ran Eudora with an 8min check, as the ISP had a
10minute inactivity time-out -- the above 24 hour/midnight drop was done
regardless of Eudora's 8min check; DSL I think I check on 30minutes)
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,289
Messages
2,571,435
Members
48,120
Latest member
Natbelix

Latest Threads

Top