Server
import socket
host = '172.19.29.83'
port = 7000
addr = (host, port)
serv_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serv_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
serv_socket.bind(addr)
serv_socket.listen(10)
print ('aguardando conexao')
con, cliente = serv_socket.accept()
print ('conectado')
print ("aguardando mensagem")
recebe = con.recv(1024)
while recebe!= "Sair": #Socket só encerra quando cliente enviar Sair
print ("mensagem recebida: ", recebe)
recebe = con.recv(1024)
else:
serv_socket.close()
Customer
import socket
ip = '172.19.29.83'
port = 7000
addr = ((ip,port))
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(addr)
mensagem = input("digite uma mensagem para enviar ao servidor")
while mensagem != "Sair":#Socket só encerra quando cliente enviar Sair
mensagem = input("digite uma mensagem para enviar ao servidor")
client_socket.send(mensagem.encode())
print ('mensagem enviada')
else:
client_socket.close()
With these codes, despite giving a very strange error in the end, I was able to get the client to send as many messages as he wants to the server, until the client types Exit and then closes the processes.
How do I pro-send a message to the client and receive the client?