From 3c64da529af1e9be2bfa04bca8aec2b5a9fd52d3 Mon Sep 17 00:00:00 2001 From: Refik Hadzialic Date: Sun, 11 Sep 2011 16:33:24 +0200 Subject: Added a special server class socket class which supports also timeout in waiting for a connection. This way I can avoid a deadlock if the web site doesn't connect to the testing software it will automatically close itself --- notFinishedCode/web/server1.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'notFinishedCode/web/server1.py') diff --git a/notFinishedCode/web/server1.py b/notFinishedCode/web/server1.py index 00c4347..42cc376 100644 --- a/notFinishedCode/web/server1.py +++ b/notFinishedCode/web/server1.py @@ -1,7 +1,9 @@ -import ServerClass +import ServerClassSoftware import random from time import sleep import dbClass +import sys + ########## #from Tkinter import * @@ -26,22 +28,38 @@ xy = dbClass.DBMySQLConnection(user, passw, host, dbname) print "connected to the DB ", xy.connectDB() print 'mutex says' , xy.lockMutex(100) -server = ServerClass.ServerHandler(34500) #define the port -tried = server.openSocket() +server = ServerClassSoftware.ServerHandlerSoftware(34500) #define the port +tried = server.openSocket(2) + +def closeFunction(dbConn,serverSocket): + print 'Release the mutex: ' + str(dbConn.releaseMutex()) + print 'Close the DB Connection: ' + str(dbConn.closeDBConn()) + del dbConn + del serverSocket + sys.exit() + + +if tried == 'TIMEOUT': + closeFunction(xy,server) test = server.receiveData(2) +if test == 'TIMEOUT': + closeFunction(xy,server) + print test if test == 'START TEST': server.sendData('CONFIRM\n') print 'TEST STARTED' rndNum = random.randint(3,7) for x in range(0,rndNum): - sleep(2) + sleep(5) print x if server.sendData('SOME TEST WAS OK ' + str(x) + chr(10)) == 1: print 'data sent successfully' test = server.receiveData(2) + if test == 'TIMEOUT': + closeFunction(xy,server) print test if test == 'CONTINUE': print 'continue test' @@ -49,6 +67,8 @@ for x in range(0,rndNum): if server.connected == 1: server.sendData('TEST DONE\n') test = server.receiveData(2) +if test == 'TIMEOUT': + closeFunction(xy,server) if test == 'DISCONNECT': close = server.closeConnection() -- cgit v1.2.3-55-g7522