summaryrefslogtreecommitdiffstats
path: root/notFinishedCode/web/server1.py
diff options
context:
space:
mode:
authorRefik Hadzialic2011-09-11 16:33:24 +0200
committerRefik Hadzialic2011-09-11 16:33:24 +0200
commit3c64da529af1e9be2bfa04bca8aec2b5a9fd52d3 (patch)
tree85ec6171877b9082f8e07ccf77f318adfccceadb /notFinishedCode/web/server1.py
parentWorked on the look of the web site! (diff)
downloadgsm-selftest-3c64da529af1e9be2bfa04bca8aec2b5a9fd52d3.tar.gz
gsm-selftest-3c64da529af1e9be2bfa04bca8aec2b5a9fd52d3.tar.xz
gsm-selftest-3c64da529af1e9be2bfa04bca8aec2b5a9fd52d3.zip
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
Diffstat (limited to 'notFinishedCode/web/server1.py')
-rw-r--r--notFinishedCode/web/server1.py28
1 files changed, 24 insertions, 4 deletions
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()