Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
EasyCom
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ethan Robert
EasyCom
Commits
eab8f20a
Commit
eab8f20a
authored
5 months ago
by
Ethan Robert
Browse files
Options
Downloads
Patches
Plain Diff
Changed teacher version in order to adapt to the API
parent
4ec77e4d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Teacher/main.py
+25
-21
25 additions, 21 deletions
Teacher/main.py
with
25 additions
and
21 deletions
Teacher/main.py
+
25
−
21
View file @
eab8f20a
import
socket
import
requests
from
time
import
sleep
MASK
=
22
...
...
@@ -14,22 +14,10 @@ RANGES = {
(
'
HEVÉA
'
,
'
4A20
'
):
[
'
172.18.49.80
'
,
'
172.18.49.107
'
],
(
'
IF
'
,
'
4A39-4A41
'
):
[
'
172.18.49.109
'
,
'
172.18.49.123
'
],
(
'
SEQUOÏA
'
,
'
4A43
'
):
[
'
172.18.49.125
'
,
'
172.18.49.132
'
],
(
'
SAULE
'
,
'
4A24
'
):
[
'
172.18.49.133
'
,
'
172.18.49.159
'
]
(
'
SAULE
'
,
'
4A24
'
):
[
'
172.18.49.133
'
,
'
172.18.49.159
'
],
(
'
DEBUG
'
):
[
'
127.0.0.1
'
,
'
127.0.0.1
'
]
}
class
Socket
:
def
__init__
(
self
,
address
):
self
.
socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
address
=
address
def
update
(
self
):
self
.
socket
.
connect
((
address
,
25566
))
message
=
self
.
socket
.
recvfrom
(
1024
).
decode
(
"
UTF-8
"
)
return
message
class
ConnectionHandler
:
def
__init__
(
self
,
room
):
...
...
@@ -44,19 +32,35 @@ class ConnectionHandler:
self
.
addresses
=
[
row
[
0
][
0
:
10
]
+
str
(
k
)
for
k
in
numbers
]
print
(
self
.
addresses
)
# Create sockets for all of these addresses
self
.
sockets
=
[
Socket
(
a
)
for
a
in
self
.
addresses
]
# Hold a message list
self
.
messages
{}
for
a
in
self
.
addresses
:
self
.
messages
[
a
]
=
""
def
update
(
self
):
for
s
in
self
.
sockets
:
print
(
s
.
update
())
changes
=
{}
for
a
in
self
.
addresses
:
response
=
requests
.
get
(
"
http://
"
+
a
+
"
:45566
"
)
message
=
response
.
content
.
decode
(
"
utf-8
"
)
if
message
!=
self
.
messages
[
a
]:
changes
[
a
]
=
messages
return
changes
connections
=
ConnectionHandler
((
"
SEQUOÏA
"
,
"
4A43
"
))
connections
=
ConnectionHandler
((
"
DEBUG
"
))
while
True
:
connections
.
update
()
changes
=
connections
.
update
()
for
c
in
changes
:
print
(
changes
[
c
])
time
.
sleep
(
30
)
print
(
"
----------------------------------------------------
"
)
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