ich wollte mal einen Chat machen aber ich finde im Internet nur ewiglange Programme(ich hasse ewiglange Programme).
Könnt ihr mir ein einfaches Beispiel hier posten?
Es soll eine Server - Client Verbindung sein.
Danke!!

Code: Alles auswählen
#!/bin/bash
touch chat.txt
tail -f chat.txt &
cat /dev/stdin >>chat.txt
Code: Alles auswählen
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("", 50000))
s.listen(1)
try:
while True:
komm, addr = s.accept()
while True:
data = komm.recv(1024)
if not data:
komm.close()
break
print("[{}] {}".format(addr[0], data.decode()))
nachricht = input("Antwort: ")
komm.send(nachricht.encode())
finally:
s.close()
Code: Alles auswählen
import socket
ip = input("IP-Adresse: ")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip, 50000))
try:
while True:
nachricht = input("Nachricht: ")
s.send(nachricht.encode())
antwort = s.recv(1024)
print("[{}] {}".format(ip, antwort.decode()))
finally:
s.close()