'A text is sent by socket non-stop, in a loop, I wanted it to be sent only once

I wrote a code that just send a pre-established text. I got it, but the text is sent endlessly, non-stop, I wanted it to be sent only once. How do I do it please?

Server

from socket import *
host = gethostname()
port = 8889

print(f'HOST: {host} , PORT {port}')
serv = socket(AF_INET, SOCK_STREAM)
serv.bind((host, port))
serv.listen(5)
while 1:
    con, adr = serv.accept()
    while 1:
        msg = con.recv(1024)
        print(msg.decode())

Client

from socket import *
host = gethostname()
port = 8889
cli = socket(AF_INET, SOCK_STREAM)
cli.connect((host, port))
while 1:
    msg = ("hi")
    cli.send(msg.encode())

The result does not stop printing the hi



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source