Bonjour à tous !
Je cherche à créer une liaison client - serveur sur python, j'ai l'erreur suivante :
rawdata = s.recv(BUFFER_SIZE)
error: [Errno 10053] Une connexion établie a été abandonnée par un logiciel de votre ordinateur hôte
Pourriez-vous m'aiguiller sur une solution à propos de ce bug ? Voici le code :
--------- SERVEUR ---------
import socket
TCP_IP = '127.0.0.1'
TCP_PORT = 55001
BUFFER_SIZE = 1024
sconn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sconn.bind((TCP_IP, TCP_PORT))
print("binding to "+ TCP_IP +":"+str(TCP_PORT)," ...")
sconn.listen(1)
print("Waiting client ...")
s, addr = sconn.accept()
print('Client connected with address:', addr)
while True:
rawdata = s.recv(BUFFER_SIZE)
print("received data:", rawdata.decode('ascii'))
s.send(rawdata.encode('ascii'))
if rawdata.decode('ascii') == 'end' :
break
time.sleep(1)
s.close()
sconn.close()
" --------- CLIENT --------- "
import socket
TCP_IP = '127.0.0.1'
TCP_PORT = 55001
BUFFER_SIZE = 1024
data = ''
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
print('connecting to '+ TCP_IP + ':' + str(TCP_PORT) +'...')
print('sending data...')
while data != 'end':
data = raw_input('Entrer un message : ')
print(data)
s.send(data.encode('ascii'))
rawdata = s.recv(BUFFER_SIZE)
print("received data:\n", rawdata.decode('ascii'))
s.close()
Ma version de Python : 2.7.14 sous Windows 7
Je vous remercie d'avance ! 