Commit c3c2e65d authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

Merge branch '49-make-myaxes-client' of gitlab.aip.de:yfournier/myplotlib into...

Merge branch '49-make-myaxes-client' of gitlab.aip.de:yfournier/myplotlib into 49-make-myaxes-client
parents 35beaaeb c3eee192
......@@ -70,7 +70,7 @@ if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
elif D_HIERARCHY in ('SERVER', 'server'):
print(INFO+'Import myplotlib as a server.')
from .config import D_HOST, D_PORT
from socket import socket, AF_INET, SOCK_STREAM
from socket import socket, AF_INET, SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR
else:
print(SEVR+'the value of D_HIERARCHY has to be SERVER or CLIENT')
......@@ -103,8 +103,7 @@ if D_HIERARCHY in ('CLIENT', 'client'):
elif(D_HIERARCHY in ('SERVER', 'server')):
# for testing purpose
from .test.myIOs import readStupidData
# MyAxes: Overlay on matplotlib.Axes class
from .myAxes_server import MyAxes_server as MyAxes
......@@ -161,3 +160,6 @@ if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
from .test import myTest
from .test import testList
# for testing purpose
from .test import readStupidData
......@@ -149,6 +149,7 @@ elif run4Plot:
elif run4server:
from .server import Server
from .test import readStupidData
server = Server()
server.init()
......
......@@ -4,7 +4,7 @@ from .myData import MyData
D_VERSION='v5'
D_HIERARCHY='SERVER'
D_HOST='localhost'
D_PORT=50228
D_PORT=50803
# FORM -----------------------------------------------------------------
INFO = " > info-: "
......
from . import socket, AF_INET, SOCK_STREAM
from . import socket, AF_INET, SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR
from . import D_HOST
from . import D_PORT
from . import INFO, DBUG, WARN, SEVR, SPCE
from . import readStupidData
G_RAWDATA = {}
class Server():
......@@ -8,11 +13,10 @@ class Server():
def __init__(self):
self.soc = socket(AF_INET, SOCK_STREAM)
self.soc.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) # requires some extra import
self.host = D_HOST
self.port = D_PORT
self.answer = None
def init(self):
self.soc.bind((self.host, self.port))
......@@ -20,63 +24,75 @@ class Server():
def run(self):
signal = False
while True:
if not self.answer:
if not signal:
conn, addr = self.soc.accept()
print(INFO + 'Connected by ' + str(addr))
self.answer = conn.recv(1024)
signal = conn.recv(1024)
if self.answer in ('KILL', 'kill', 'Kill'):
if signal in ('KILL', 'kill', 'Kill'):
print(INFO+"Recieved 'Kill' signal.")
conn.close()
break
elif signal != '':
answer = self.treatAnswer(signal)
conn.sendall(str(answer))
else:
answer = self.treatAnswer()
self.soc.sendall(answer)
pass
def treatAnswer(self):
def treatAnswer(self, signal):
answer = None
try:
(header, content) = exec(str(self.answer))
(header, content) = eval(str(signal))
except:
print(WARN+"I could not execute the command")
print(SPCE+'Received: '+str(self.answer))
print(SPCE+'Received: '+str(signal))
print(SPCE+"I expect '(header, content)'")
answer = ('readData', None, 'answer not correct format')
return(answer)
if header in ('readData', 'READATA', 'readdata'):
if header in ('readData', 'READDATA', 'readdata'):
try:
(dataName, functionName, args, kwargs) = exec(str(content))
(dataName, functionName, args, kwargs) = eval(str(content))
except:
print(WARN+"The content of readData could not be extracted")
print(SPCE+'Received: '+str(content))
print(SPCE+"I expect '(dataName, functionName, args, kwargs)'")
answer = ('readData', None, 'could not extract content')
return(answer)
try:
print(str(functionName)+'('+str(args)+', '+str(kwargs)+')')
if args is not None:
if kwargs is not None:
G_RAWDATA[dataName] = exec(str(functionName)+'('+str(args)+', '+str(kwargs)+')')
G_RAWDATA[dataName] = eval(str(functionName)+'('+str(args)+', '+str(kwargs)+')')
else:
G_RAWDATA[dataName] = exec(str(functionName)+'('+str(args)+')')
G_RAWDATA[dataName] = eval(str(functionName)+'('+str(args)+')')
else:
if kwargs is not None:
G_RAWDATA[dataName] = exec(str(functionName)+'('+str(kwargs)+')')
G_RAWDATA[dataName] = eval(str(functionName)+'('+str(kwargs)+')')
else:
G_RAWDATA[dataName] = exec(str(functionName)+'()')
G_RAWDATA[dataName] = eval(str(functionName)+'()')
answer = ('readData', 'dataName', 'no error')
print(G_RAWDATA[dataName].data)
answer = ('readData', dataName, 'no error')
except:
print(WARN+"The read function could not be executed")
answer = ('readData', None, 'function could not be executed')
return(answer)
else:
print(WARN+"I don't know ths signal, sorry")
answer = ('readData', None, 'signal unknown')
return(answer)
return(answer)
......@@ -12,14 +12,14 @@ if D_HIERARCHY in ('CLIENT', 'client'):
# ]
elif D_HIERARCHY in ('SERVER', 'server'):
pass
# from .axTestServer import AxTestServer
# from .figTestServer import FigTestServer
# from .tests_server import myTest
# from .tests_server import test100
from .axTestServer import AxTestServer
from .figTestServer import FigTestServer
from .tests_server import myTest
from .tests_server import test100
testList = [test100,
]
# testList = [test100,
# ]
elif D_HIERARCHY in ('local', 'LOCAL'):
......
Markdown is supported
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