import socket from threading import Thread class SimpleProgram(Thread): def __init__(self): Thread.__init__(self) self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket.bind(('localhost', 9000)) self.socket.listen(5) self.setDaemon(True) self.start() def run(self): while True: try: client, addr = self.socket.accept() data = client.recv(1024).decode() print(data) client.shutdown(socket.SHUT_RDWR) client.close() except socket.error: print("Hiba! A foglalat létrehozás sikertelen!") try: self.socket.shutdown(socket.SHUT_RDWR) except: pass self.socket.close() prog = SimpleProgram() prog.run()