473,388 Members | 1,256 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,388 software developers and data experts.

socket freezes

-----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

iD8DBQFECEF8Hn4UHCY8rB8RAtaaAKCnFb2O28AE4uRTK0sPSp nOifaDzACdG2EA
imVqvzcRX4qGWqMzLRUcyao=
=Cqkb
-----END PGP SIGNATURE-----
Mar 3 '06 #1
6 2003
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
:-)

--
René Pijlman
Mar 3 '06 #2
Luis P. Mendes wrote:
-----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
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com

Mar 3 '06 #3
-----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

iD8DBQFECKMmHn4UHCY8rB8RAoeAAJ92sEUsFk2bsXcCX77cDy HY2jOogwCgnGKZ
xStEmoEDTDrhVE7+aIAxSbI=
=qzed
-----END PGP SIGNATURE-----
Mar 3 '06 #4
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

Mar 4 '06 #5
Dennis Lee Bieber wrote:
On Fri, 03 Mar 2006 20:12:22 +0000, "Luis P. Mendes"
<lu***********@netvisaoXXX.pt> declaimed the following in
comp.lang.python:
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).

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
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com

Mar 4 '06 #6
-----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

iD8DBQFECb5AHn4UHCY8rB8RAmeLAKCmSVfTvgQ94NPnJlD2Qq dbMwVFXACdGFAh
8GL/9zxwXCYcmWxpyDweggE=
=9U0o
-----END PGP SIGNATURE-----
Mar 4 '06 #7

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

Similar topics

0
by: Enterprise | last post by:
Hi, I use Access 2000. FEBE design. Tables on server, and everything else on local machine. I have 1 table with a primary key ID field and a text field with names in it. This table is like a...
1
by: st8 | last post by:
Hi I'm trying to make a basic news reader and have a little problem. When it downloads the group list if freezes after about 120 groups and nothing happens for about a minute. Then I get "503...
1
by: Yahya Saad | last post by:
Dear All, I have upgraded and application I developed on VB6 which uses the Mscomm1 component and reads from COM1 port data send, then sends these records to a table in SQL 2000. I upgraded the...
0
by: Daniel | last post by:
C# windows service freezes on System.Diagnostics.Process.Start(info) When I launch PSCP from a C# windows service and launch pscp 0.53 there are no issues. but when I use C# windows service to...
0
by: genojoe | last post by:
I am running an application that, when not used, just sits there firing a BackgroundWorker every 20 seconds. Every now and then, the BackgroundWorker freezes between the DoWork and...
3
by: Erakis | last post by:
Hi, I have to make an ActiveX (Running on Internet Explorer) that play/record sound from soundcard. Also, I have to create a Socket to send/receive sound data to my server. I use this...
0
by: Marcin Szarek | last post by:
Hi! For a few months we suffer mysterious problem with Oracle 10g RAC (more details on server configuration at the bottom). At regular basis (every 5 minutes) nodes of our cluster "freeze" -...
0
by: Blog the Haggis | last post by:
Hi all, I've written a program which distributes binary data to a number of clients via TCP. The program runs perfectly unless one of the client programs hangs and then it freezes while waiting...
10
by: John Salerno | last post by:
I wrote some pretty basic socket programming again, but I'm still confused about what's happening with the buffer_size variable. Here are the server and client programs: -------------- from...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.