Démonstration de communication asynchrone.
from random import * def encode(txt,key): return "".join([chr((ord(c)-97+key)%26+97) for c in txt]) class Deck(): def __init__(self): self.deck=["pikachu","tranchodon"] self.wait_sending=[] self.wait_reception=[] self.key=randint(0,25) def start_sending(self,pk): if pk in self.deck: self.wait_sending+=[pk] return encode(pk,self.key) def start_reception(self,msg): self.wait_reception+=[msg] return msg+"-"+encode(msg,self.key) def end_sending(self,msg): pk=encode(msg.split("-")[0],-self.key) if pk in self.wait_sending: self.wait_sending.remove(pk) self.deck.remove(pk) return msg.split("-")[0]+"-"+encode(msg.split("-")[1],-self.key) def end_reception(self,msg): pk_c=msg.split("-")[0] if pk_c in self.wait_reception: self.wait_reception.remove(pk_c) self.deck+=[encode(msg.split("-")[1],-self.key)]