Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rdos
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien David
rdos
Commits
8a9bd677
Commit
8a9bd677
authored
4 years ago
by
Ismail Moumni
Browse files
Options
Downloads
Patches
Plain Diff
sending gen json
parent
a85102c7
No related branches found
No related tags found
1 merge request
!5
Adding json functions
Pipeline
#633
failed
4 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
softwares/server/server.py
+35
-27
35 additions, 27 deletions
softwares/server/server.py
with
35 additions
and
27 deletions
softwares/server/server.py
+
35
−
27
View file @
8a9bd677
# authors: Julien DAVID & Ismail MOUMNI
import
socket
import
json
# SERVER PORT
import
sys
import
os
sys
.
path
.
append
(
os
.
path
.
realpath
(
'
../softwares/
'
))
# from database.database import getParameters
# SERVER PORT
__RDOS_Port__
=
9393
# Dictionnary
__RDOS_Dict__
=
{}
# Dictionnary
# Need to connect to MYSQL DB
__RDOS_Dict__
=
{
"
ismail
"
:
"
moumni
"
}
# tools List
__RDOS_Tool__
=
[]
# tools List
__RDOS_Tool__
=
[
"
name
"
]
# Creating Socket IP4 TCP
# Creating Socket IP4 TCP
def
server_conn
(
address
,
PORT
):
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
serv
:
serv
.
bind
((
address
,
PORT
))
...
...
@@ -21,39 +25,43 @@ def server_conn(address, PORT):
serv
.
listen
(
5
)
print
(
"
ok
"
)
# accepting the connection from client and getting client IP
conn
,
addr
=
serv
.
accept
()
conn
,
addr
=
serv
.
accept
()
print
(
"
connexion accepted
"
)
with
conn
:
conn
.
send
(
bytes
(
"
Bonjour !!
"
,
"
utf-8
"
))
print
(
'
Connexion acceptée depuis l IP :
'
,
addr
)
# Receiving Data from Client
data
=
conn
.
recv
(
4096
)
print
(
data
)
if
query_valid
(
data
)
==
"
True
"
:
query
=
(
json
.
loads
(
data
.
decode
(
'
utf-8
'
)))
print
(
query
)
if
query_valid
(
query
):
dt_js
=
json
.
dumps
(
send_param_client
(
__RDOS_Dict__
,
__RDOS_Tool__
))
conn
.
send
(
dt_js
)
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
# 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
):
if
'
parameters
'
in
data
:
if
(
data
[
'
parameters
'
]
==
'
request
'
)
&
(
len
(
data
)
<
2
):
return
True
return
False
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
# 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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment