By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,929 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,929 IT Pros & Developers. It's quick & easy.

connection to server not accepted (but no error) only after several hours

P: n/a
seb
Hi, this simple server (time protocol) does not respond after a few
hours, even when it is restarted. The behaviour looks to me like a
firewall blocking but I have desabled the firewall.
Using Netstat - a I find the server listed when it is running and not
listed when I stop it.
The server starts whith no error. But after about 6-8 hours there is no
way to make it respond again (even when it is restarted).

Once it is blocked, I killes it, wait for about 15 minutes without
running the server and then started again but this gives me the same
behaviour (no response).

The solution at this time is to reboot windows !!!

I have also tried to run it twice in order to get the exception that
the port is already used and an exeption is raised.
I have tried from another computer to connect to mine but it does not
manage.
When I change the port in the server it responds immediatly.

I am running winXP SP2, python 2.4.

Do you have any clues ?
Thanks in advance.
Seb.

PS : I am calling this server from another program and make it run in a
thread.
Below is the standalone version (wich is adpated from effbot site).

import socket
import struct, time
import threading
import os
import appel_log2 as appel_log
import sys
class TimeServer(threading.Thread) :
def __init__(self):
nom_function_actuelle= str(sys._getframe().f_code.co_filename)
+"___"+str(sys._getframe().f_code.co_name)
try :
threading.Thread.__init__(self)
self.log_file="timeserverlog.txt"
self.PORT=37
self.TIME1970=2208988800L
self._continue=1
self.time_shift=0
message=nom_function_actuelle+"\t "+"STARTED OK "
appel_log.write_log("info",message)
except Exception, e :
message=nom_function_actuelle+"\t "+"PB:::"+str(e)
print message
appel_log.write_log("warning",message)

def set_log_file(self, file):
nom_function_actuelle= str(sys._getframe().f_code.co_filename)
+"___"+str(sys._getframe().f_code.co_name)
if os.path.exists(file):
pass
else :
f=open(file,"w")
f.close()
self.log_file=file
print "log file ",self.log_file
self.log_file=file

def reset_log_file(self):
nom_function_actuelle= str(sys._getframe().f_code.co_filename)
+"___"+str(sys._getframe().f_code.co_name)
print "resetting log file "
if os.path.exists(self.log_file):
f=open(self.log_file,"w")
f.close()

def set_time_shift(self,time_shift):
self.time_shift=time_shift

def run(self):
nom_function_actuelle= str(sys._getframe().f_code.co_filename)
+"___"+str(sys._getframe().f_code.co_name)
socket.timeout(1)
service=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
service.bind(("", self.PORT))
service.listen(1)
print "listening on port", self.PORT
while self._continue==1 :
channel, info = service.accept()
print "connection from", info
message=str(time.time())+"\t"+str(time.asctime())+ "\t"+str(info)+"\n"
g=open(self.log_file,"a")
g.write(message)
g.close()
t = int(time.time()) + self.TIME1970 + self.time_shift
t = struct.pack("!I", t)
channel.send(t) # send timestamp
channel.close() # disco
m=nom_function_actuelle+" response OK "+str(info)
appel_log.write_log("info",m)
#print "apres m "
print "time server self_continue=0"
appel_log.write_log("warning",nom_function_actuell e+"\t
self._continue ="+str(self._continue))
print "sortie du thread"

def main() :
a=TimeServer()
a.start()
a.set_log_file("log_nw.txt")
a.reset_log_file()
while 1==1 :
time.sleep(10)
#a._continue=0
pass
time.sleep(2)

main()

Jan 16 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
seb
Hi Dennis,

I am using indeed using python logging in the appel_log2 module.
But I wanted to keep it extremly simple while accepting connection from
different processes or thread.

Regarding my main problem, I did some more testing :

1) I have enabled one time server that can be run as a service (R C C
time server) and this service is responding correctly, when at the same
time (before I kill it ) the python time server is not responding.

2) I have also tried two python time server downloaded from effbot
site. Both are not responding after the "non response from the time
server I rn" even for the first interrogation once they are started.
(Of course I have killed my time server when I run a new one).
Same behaviour no response given but no error neither.

3)
If I try to start the R c c time server when the python time server is
running there is an error (from the rcc service)
The python time server program is really bound to port 37.

if we look at the previous tests :

4)
The same python program runned on port 38 aftter the blocking is
working properly from the start.

5)
There is no exception on the python time server whether it is
responding or not.

--------------------------
partial conclusion
-------------------------

It is only python programs that are listening from the port 37 that are
blocked at a certain time.
How is it possible (without firewall enabled) ?

Thanks .
Sebastien.
Dennis Lee Bieber a écrit :
On 16 Jan 2007 07:39:35 -0800, "seb" <se************@laposte.net>
declaimed the following in comp.lang.python:

Once it is blocked, I killes it, wait for about 15 minutes without
running the server and then started again but this gives me the same
behaviour (no response).
Can't help with the lock-up problem... but...

import socket
import struct, time
import threading
import os
import appel_log2 as appel_log
import sys
class TimeServer(threading.Thread) :
def __init__(self):
nom_function_actuelle= str(sys._getframe().f_code.co_filename)
+"___"+str(sys._getframe().f_code.co_name)
try :
threading.Thread.__init__(self)
self.log_file="timeserverlog.txt"
self.PORT=37
self.TIME1970=2208988800L
self._continue=1
self.time_shift=0
message=nom_function_actuelle+"\t "+"STARTED OK "
appel_log.write_log("info",message)

Have you considered using Python's logging module?
while 1==1 :

Redundant test...

In all historical versions of Python

while 1:

sufficed, and newer versions have

while True:
--
Wulfraed Dennis Lee Bieber KD6MOG
wl*****@ix.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@bestiaria.com)
HTTP://www.bestiaria.com/
Jan 17 '07 #2

P: n/a
seb
Hi Dennis,

I think I have some new informations.
My system is "blocked" now but the following change make it work again
!!!
I will test it for tonight to be sure of the improvements.

I changed :
service.bind(("", self.PORT))
to
service.bind((socket.gethostname(), self.PORT))

The strange thing is that using the "" it works for a few hours.

Regards.
Sebastien.
Dennis Lee Bieber a écrit :
On 17 Jan 2007 00:08:52 -0800, "seb" <se************@laposte.net>
declaimed the following in comp.lang.python:

1) I have enabled one time server that can be run as a service (R C C
time server) and this service is responding correctly, when at the same
time (before I kill it ) the python time server is not responding.

What behavior do you see if you don't run them as background
services, but rather from a regular console login?
2) I have also tried two python time server downloaded from effbot
site. Both are not responding after the "non response from the time
server I rn" even for the first interrogation once they are started.
(Of course I have killed my time server when I run a new one).
Same behaviour no response given but no error neither.
If you've now got a total of three programs that are not reporting
error conditions, I'd suspect there is something else wrong in the
system...
It is only python programs that are listening from the port 37 that are
blocked at a certain time.
How is it possible (without firewall enabled) ?
What response do you get from the clients attempting to connect to
this server? (I'd expect a either a flat out "denied" or, for a
stealthed firewall, a timeout with no response).
You also have a race condition in your log-file...
a.start()
a.set_log_file("log_nw.txt")
a.reset_log_file()

It is possible that the thread gets a few connections between the
.start() and the .set_log_file() and logs them to the default file name.
Also, it is possible for connections to be logged between the
.set_log_file() and the .reset_log_file() (where you wipe out the
contents of the log file).

I'd suggest putting the .start() call third in that list. That way
you create the thread object, but it is not running. Change the log file
name, wipe out any old contents, and THEN start the thread running.

My only other comment would be to add a few wolf-fences... Print
statements (if running in a console), or more logging messages (you
might want to make a method out of that internal logging so all you code
is, say

self.slog("message")

and "slog" does that time stamping, and file open/close...

By logging each main step (accept, send, close) you might find where
it stops.
--
Wulfraed Dennis Lee Bieber KD6MOG
wl*****@ix.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@bestiaria.com)
HTTP://www.bestiaria.com/
Jan 18 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.