Commit 95335d26 authored by Yori Fournier's avatar Yori Fournier
Browse files

test a new client and server

parent 0443382a
......@@ -19,7 +19,6 @@ class MplClient2():
self.currentRemoteData = []
def connect(self,con):
self.host,self.port = con # give (IP,PORT)
self.sock = socket(AF_INET,SOCK_STREAM)
self.sock.connect(con)
......@@ -94,22 +93,29 @@ class MplClient2():
def readData(self,ioFunction, dataName, *args, **kwargs) :
# create a Signal of type Query with arguments
self.connect()
query = Query(Query.READDATA,{'func' : ioFunction, 'dataname' : dataName,'args' : args,'kwargs': kwargs})
status = self.send(query)
if not status :
print('something went wrong with the sending of readData request...')
statusSig = self.waitForSignal()
self.disconnect()
return self.testStatusSig(query,statusSig)
def listRemoteData(self):
""" The server retuns a list with the content of its G_RAWDATA
"""
self.connect()
query = Query(Query.LISTDATA,None)
status = self.send(query)
if not status :
print('something went wrong with the sending of readData request...')
answer = self.waitForSignal()
self.disconnect()
if isinstance(answer,Answer) :
return answer.content
elif isinstance(answer,Status):
......@@ -120,11 +126,15 @@ class MplClient2():
""" The server returns the actual data known under "dataname" warning: this can possibly be HUGE
"""
self.connect()
query = Query(Query.GETDATA,dataname)
status = self.send(query)
if not status :
print('something went wrong with the sending of readData request...')
answer = self.waitForSignal()
self.disconnect()
if isinstance(answer,Answer) :
return answer.content
elif isinstance(answer,Status):
......@@ -137,6 +147,9 @@ class MplClient2():
wait for the status.
if status ok then sync.
'''
self.connect()
# create a Signal of type Query with args
query = Query(Query.NEWSYNCFIGURE,{'figClassName' : figname.__name__, "dataName" : dataname, 'args' : args, 'kwargs' : kwargs})
status = self.send(query)
......@@ -144,6 +157,8 @@ class MplClient2():
if not status :
print('something went wrong with the sending of newSincFigure request...')
answer = self.waitForSignal()
self.diconnect()
# try to create a figure of the same class on the client side
if isinstance(answer,Answer) :
......@@ -167,11 +182,16 @@ class MplClient2():
wait for the status
if status ok then sync.
'''
self.connect()
# create a signal with args
query = Query(Query.UPDATESYNCFIGURE,(syncID,kwargs))
self.send(query)
statusSig = self.waitForSignal()
self.disconnect()
if statusSig.value :
return True
else:
......@@ -185,11 +205,17 @@ class MplClient2():
wait for the confirmation status
if status ok then proceed deletion.
'''
self.connect()
# create a signal with syncID as content
query = Query(Query.DELETESYNCFIGURE,syncID)
status = self.send(query)
statusSig = self.waitForSignal()
self.disconnect()
if status and statusSig.value:
return True
else:
......@@ -204,16 +230,20 @@ class MplClient2():
if answer not empty then set data to answer's value.
'''
self.connect()
# Send the signal with syncID as content
signal = Query(Query.SYNCFIGFORMATRAWDATA,syncID)
status = self.send(signal)
if debug:
if not status:
print(INFO+'Sent Signal')
formatedData = self.waitForSignal()
self.disconnect()
if not isinstance(formatedData,Answer) :
print(WARN + 'The server could not format the rawdata.')
......
......@@ -234,20 +234,17 @@ class MplHandler(SocketServer.StreamRequestHandler):
def handle(self):
# self.rfile is a file-like object created by the handler;
# we can now use e.g. readline() instead of raw recv() calls
## self.data = self.rfile.readline()#.strip()
while self.server.running :
unpickler = MplUnpickler(self.rfile)
request = unpickler.load()
reply = self.treatSig(request)
# Likewise, self.wfile is a file-like object used to write back
# to the client
## self.wfile.write(self.data.upper())
if isinstance(reply,Signal) :
if DEBUG:
self.servPrint("returning {}-Signal:".format(type(reply)))
pickle.dump(reply,self.wfile)
unpickler = MplUnpickler(self.rfile)
request = unpickler.load()
reply = self.treatSig(request)
if isinstance(reply,Signal) :
if DEBUG:
self.servPrint("returning {}-Signal:".format(type(reply)))
pickle.dump(reply,self.wfile)
self.wfile.close()
self.rfile.close()
class MplServer2(SocketServer.TCPServer):
......@@ -280,7 +277,6 @@ class MplServer2(SocketServer.TCPServer):
self.server_thread = threading.Thread(target=self.serve_forever)
self.server_thread.daemon = as_daemon
self.server_thread.start()
self.running = True
def stop(self): # not yet working
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment