Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
Jeopardy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Hacksaar
Jeopardy
Commits
d4a65d8f
Commit
d4a65d8f
authored
Apr 21, 2015
by
Agrigor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor changes and trials
parent
b138e2f9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
29 deletions
+42
-29
.gitignore
.gitignore
+1
-0
client/client.py
client/client.py
+38
-25
server/server.py
server/server.py
+3
-4
No files found.
.gitignore
View file @
d4a65d8f
*.kde*
.kde*/
.idea
\ No newline at end of file
client/client.py
View file @
d4a65d8f
...
...
@@ -14,11 +14,40 @@ import threading
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PORT
=
50000
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~ CLASS DEFINITION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class
Connection
:
def
__init__
(
self
,
ip
,
port
):
self
.
ip
=
ip
self
.
port
=
port
self
.
socket
=
""
def
check_ip
(
self
):
try
:
socket
.
inet_aton
(
self
.
ip
)
return
True
except
socket
.
error
:
print
(
"First argument was no valid IP-address"
)
sys
.
exit
(
1
)
def
create_client_socket
(
self
):
self
.
socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
self
.
socket
.
bind
((
""
,
self
.
port
))
def
receive
(
self
,
bytes
):
daten
,
addr
=
self
.
socket
.
recvfrom
(
bytes
)
if
addr
[
0
]
==
self
.
ip
:
print
(
addr
[
0
]
+
" -> "
+
daten
.
decode
())
else
:
print
(
"Any hacker (IP: "
+
addr
[
0
]
+
") tries to kidding me, now I'll kill him!"
)
def
cleanup
(
self
):
self
.
socket
.
close
()
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
...
@@ -28,36 +57,20 @@ import threading
class
Client
:
def
__init__
(
self
,
ip
,
port
):
self
.
source_ip
=
ip
self
.
port
=
port
# Initialize source ip adress
try
:
socket
.
inet_aton
(
self
.
source_ip
)
except
socket
.
error
:
print
(
"First argument was no valid IP-address"
)
sys
.
exit
(
0
)
else
:
self
.
UDP
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
self
.
UDP
.
bind
((
""
,
self
.
port
))
def
cleanup
(
self
):
self
.
UDP
.
close
()
print
(
"
\n
Bye Bye"
)
sys
.
exit
(
0
)
self
.
foo
=
Connection
(
ip
,
port
)
if
self
.
foo
.
check_ip
():
self
.
foo
.
create_client_socket
()
def
main
(
self
):
try
:
self
.
daten
,
self
.
addr
=
self
.
UDP
.
recvfrom
(
1024
)
if
self
.
addr
[
0
]
==
self
.
source_ip
:
print
(
self
.
addr
[
0
],
self
.
daten
.
decode
())
else
:
print
(
"Any hacker (IP: "
+
self
.
addr
[
0
]
+
") tries to kidding me, now I'll kill him!"
)
except
OSError
:
print
(
"...no connection..."
)
time
.
sleep
(
1
)
self
.
foo
.
receive
(
1024
)
finally
:
self
.
cleanup
()
def
cleanup
(
self
):
print
(
"
\n
Bye Bye"
)
sys
.
exit
(
0
)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PROGRAM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
...
@@ -65,7 +78,7 @@ class Client:
# Start Client
client
=
Client
(
sys
.
argv
[
1
],
50000
)
client
=
Client
(
sys
.
argv
[
1
],
PORT
)
client
.
main
()
...
...
server/server.py
View file @
d4a65d8f
...
...
@@ -4,7 +4,6 @@
import
RPi.GPIO
as
GPIO
import
time
import
sys
import
socket
import
threading
...
...
@@ -35,7 +34,7 @@ class Connection:
self
.
socket
.
close
()
def
send
(
self
,
message
):
self
.
socket
.
sendto
(
str
.
encode
(
self
.
msg
),
(
self
.
target_ip
,
self
.
target_port
))
self
.
socket
.
sendto
(
str
.
encode
(
message
),
(
self
.
target_ip
,
self
.
target_port
))
def
observe_buzzers
(
self
,
buzzers
):
for
buzzer
in
buzzers
:
...
...
@@ -80,12 +79,12 @@ class Server:
self
.
connection
=
Connection
(
ip
,
port
)
self
.
buzzers
=
[
Buzzer
(
i
,
pin
,
BOUNCE
)
for
i
,
pin
in
enumerate
(
BUZZER_PINS
,
start
=
1
)]
self
.
connection
.
observe_buzzers
(
self
.
buzzers
)
# Initialize target ip adress
# Initialize target ip ad
d
ress
try
:
socket
.
inet_aton
(
ip
)
except
socket
.
error
:
print
(
"First Argument was no valid IP-Address"
)
sys
.
exit
(
0
)
sys
.
exit
(
1
)
def
cleanup
(
self
):
GPIO
.
cleanup
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment