Commit 2bb9fba6 authored by Ismail Moumni's avatar Ismail Moumni
Browse files

adding server class

parent 8a9bd677
Pipeline #634 failed with stage
in 13 seconds
......@@ -16,52 +16,52 @@ __RDOS_Dict__ = {"ismail":"moumni"}
# tools List
__RDOS_Tool__ = ["name"]
class server:
# Creating Socket IP4 TCP
def server_conn(address, PORT):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
serv.bind((address, PORT))
# Listening to 5 CLients
serv.listen(5)
print("ok")
# accepting the connection from client and getting client IP
conn, addr = serv.accept()
print("connexion accepted")
with conn:
print('Connexion acceptée depuis l IP : ', addr)
# Receiving Data from Client
data = conn.recv(4096)
query = (json.loads(data.decode('utf-8')))
print(query)
if query_valid(query):
dt_js = json.dumps(send_param_client(__RDOS_Dict__, __RDOS_Tool__))
print(dt_js)
conn.send(bytes((dt_js),"utf-8"))
serv.close()
# Creating Socket IP4 TCP
def server_conn(address, PORT):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
serv.bind((address, PORT))
# Listening to 5 CLients
serv.listen(5)
print("ok")
# accepting the connection from client and getting client IP
conn, addr = serv.accept()
print("connexion accepted")
with conn:
print('Connexion acceptée depuis l IP : ', addr)
# Receiving Data from Client
data = conn.recv(4096)
query = (json.loads(data.decode('utf-8')))
print(query)
if query_valid(query):
dt_js = json.dumps(send_param_client(__RDOS_Dict__, __RDOS_Tool__))
print(dt_js)
conn.send(bytes((dt_js),"utf-8"))
serv.close()
# Function query_valid matches the query send from client side
# with the the parameter dict
# Function input dictionnary from client
# Function output boolean true if match else False
def query_valid(data: dict):
if 'parameters' in data:
if (data['parameters'] == 'request') & (len(data) < 2):
return True
return False
# Function query_valid matches the query send from client side
# with the the parameter dict
# Function input dictionnary from client
# Function output boolean true if match else False
def query_valid(data: dict):
if 'parameters' in data:
if (data['parameters'] == 'request') & (len(data) < 2):
return True
return False
# Function send_param_client send a dictionnary containing parameters
# needed to add a query to db
# Function exmaple s = {"ARGUMENTS","Tools":"List of Tools" }
# Function input takes dictionnary and a list of tools
# Function output returns a new dictionnary containing arguments
# # for db query and list of tools
def send_param_client(__RDOS_Dict__: dict, __RDOS_Tools__: list):
dict_cl = {}
if len(__RDOS_Dict__) > 0:
dict_cl["outils"] = (__RDOS_Tools__)
s = {**__RDOS_Dict__, **dict_cl}
return s
# Function send_param_client send a dictionnary containing parameters
# needed to add a query to db
# Function exmaple s = {"ARGUMENTS","Tools":"List of Tools" }
# Function input takes dictionnary and a list of tools
# Function output returns a new dictionnary containing arguments
# # for db query and list of tools
def send_param_client(__RDOS_Dict__: dict, __RDOS_Tools__: list):
dict_cl = {}
if len(__RDOS_Dict__) > 0:
dict_cl["outils"] = (__RDOS_Tools__)
s = {**__RDOS_Dict__, **dict_cl}
return s
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