Server und Client für Protokolle fertig
This commit is contained in:
parent
530cb7dfd3
commit
e6ac9acf6e
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"python.pythonPath": "venv/bin/python3"
|
||||||
|
}
|
24
protocol-client.py
Normal file
24
protocol-client.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import socket
|
||||||
|
|
||||||
|
HOST = socket.gethostname()
|
||||||
|
PORT = 60000
|
||||||
|
|
||||||
|
SOCKET = socket.socket()
|
||||||
|
|
||||||
|
msg = input("Your Message: ")
|
||||||
|
|
||||||
|
SOCKET.connect((HOST, PORT))
|
||||||
|
SOCKET.send(msg.encode("utf-8"))
|
||||||
|
|
||||||
|
recv_msg = ""
|
||||||
|
while True:
|
||||||
|
data = SOCKET.recv(16)
|
||||||
|
if data:
|
||||||
|
recv_msg += data.decode("utf-8")
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
print(recv_msg)
|
||||||
|
|
||||||
|
SOCKET.close()
|
22
protocol-server.py
Normal file
22
protocol-server.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#! /usr/bin/env python
|
||||||
|
|
||||||
|
import socket
|
||||||
|
|
||||||
|
HOST = socket.gethostname()
|
||||||
|
PORT = 60000
|
||||||
|
|
||||||
|
SOCKET = socket.socket()
|
||||||
|
|
||||||
|
try:
|
||||||
|
SOCKET.bind((HOST, PORT))
|
||||||
|
SOCKET.listen()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
conn, addr = SOCKET.accept()
|
||||||
|
msg = conn.recv(1024)
|
||||||
|
upper_msg = msg.decode("utf-8").upper()
|
||||||
|
print(upper_msg)
|
||||||
|
conn.send(upper_msg.encode("utf-8"))
|
||||||
|
conn.close()
|
||||||
|
finally:
|
||||||
|
SOCKET.close()
|
Loading…
x
Reference in New Issue
Block a user