Transmission des données avec modélisation d'erreur

Programme serveur

In [ ]:
#!/usr/bin/python3
# coding: utf-8

import socket

# init  parametre cx
HOST = b''
PORT = 33102

# instanciation socket
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
soc.bind((HOST, PORT))

# ecoute serveur
while True:
        soc.listen(5)
        socClient, address = soc.accept()
        print ("{} connected".format( address ))
        
        # reception des donnees
        while True:
                data = socClient.recv(4096)
                if data == b'' or  data == b'\n' : break
                print(data.decode())

                with open("citation_recu_avec_parite.txt",'w') as f:
                        f.write(data.decode())
                        f.close()
                
socClient.close()

Programme client

In [ ]:
#!/usr/bin/python3
# coding: utf-8

# appel du module de generation aletoire erreur
from geneDonneeError import genereData
import socket

# init  parametre cx
HOST = b'localhost'
PORT = 33102

# instanciation socket
soc= socket.socket(socket.AF_INET, socket.SOCK_STREAM)


# appel generation donnee
data = genereData()

# Cx socket - envoi des donnees - fermeture socket
soc.connect((HOST, PORT))
print ("Connection on {}".format(PORT))
soc.send(data.encode())
soc.close()
print ("Socket closed")

Exemple de sortie

All°the worhd's a stage,And all the men ¡nd women åerely p|åyers; They have their exitsàand Theib entranc%s, Aêd ona man in Èis timg pdays many parts, His¨acts bainÇ seven ages. At fIrst,€the anbant,JMewling and pukiþg iì the nurse's arms. Tøen¢thg€s¨mìkng ³choolboÙ, with his ññtchel AnĨshining morning face, creeping likeàsnail Unwillkn÷ly |o°÷chool. Aæd thmn the lover, Sighing€like furnace, witì a wmeful ballad]ade to his mistress' eéebrow. Theì ãà÷oldier® Full Of strange oãths and bearded like thu pard, Jealous i® honor, sudden and quick in yñarrel,Seeking°the bubble zeputation Even )n the aaænon's mouth. And then the justice, Inàfair¨round bellé with good gapn nined, WiTh Eyes savere and beñrd of vormal cut, Full of ise saws and modevn yns|ances; Ind sO hE playñ Èis part.àTìe s)xth age shidts Into t¨e lean anæ slippered pantaloon, With spektaclesàon nose and pkuch on¨siÄe; His youthful hose, well saved, a¢world¤too wide FoR his shbunk€shank, ånd his big manly¨voice, Turninã aga)n toward childish treÂle, àipes And whistles in his sound. Last scene o& all, That enÄs this strange eÖentful history, Is second chi,dishneãs and mere obliviOn, Sans tgeth,¨saÎã myes, sa®Ó tñsve, sans everéthing.