Browse Source

Server und Client für Protokolle fertig

devel
Lennart Heimbs 4 years ago
parent
commit
e6ac9acf6e
3 changed files with 49 additions and 0 deletions
  1. 3
    0
      .vscode/settings.json
  2. 24
    0
      protocol-client.py
  3. 22
    0
      protocol-server.py

+ 3
- 0
.vscode/settings.json View File

@@ -0,0 +1,3 @@
{
"python.pythonPath": "venv/bin/python3"
}

+ 24
- 0
protocol-client.py View 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
- 0
protocol-server.py View 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…
Cancel
Save