This commit is contained in:
2023-04-20 06:17:41 +02:00
parent 3871bb8d99
commit 601b5de46d
14 changed files with 783 additions and 0 deletions

60
teil13/fibclient.py Normal file
View File

@@ -0,0 +1,60 @@
# encoding: utf-8
# fibclient.py
import socket
import time
from network.const import __ADDRESS__
DISCONNECT_MESSAGE = "!DISCONNECT"
# Verbindung herstellen
def connect():
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(__ADDRESS__)
return client
# msg senden
def send(client, msg):
message = msg.encode('utf-8')
client.send(message)
# Daten empfangen
def receive(conn):
msg = conn.recv(64).decode('utf-8')
return msg
# Hauptmethode
def start():
# String von Console lesen
answer = input('Verbindung aufbauen? (ja/nein)? ')
if answer.lower() != 'ja':
return
# Verbindung aufbauen
connection = connect()
while True:
msg = input("Nachricht (q für quit): ")
# Bei Eingabe == 'q' Schleife beenden.
if msg == 'q':
break
# Sonst eingegeben String an Server senden.
send(connection, msg)
# und auf Ergebnis warten.
result = receive(connection)
print(f'result={result}')
# Fibonaccizahl isolieren.
fib = int(result.split('[')[0])
print(f'Fibonnaci-Zahl ist {fib}')
print(f'[RESULT] {result}')
# zum Beenden die Nachricht 'quit an den Server senden
send(connection, 'quit')
time.sleep(1)
print('Disconnected')
# Hauptprogramm: Client starten
if __name__ == '__main__':
start()