The operation of python socket TCP instance has been unsuccessful.

this is the client of the instance

from socket import *

HOST="localhost"
PORT=10001
BUFFER=1024
ADDRESS=(HOST,PORT)

clientSocet=socket(AF_INET,SOCK_STREAM)
clientSocet.connect(ADDRESS)
while True:
    data=input(">")
    if not data:
        break
    clientSocet.send(data.encode())
    data=clientSocet.recv(BUFFER).decode()
    if not data:
        break
    print(data)
clientSocet.close()

The

run shows the above error.

Aug.08,2021

put the code in the file and use python file.py to execute

or

add a new line before clientSocet.close () , because in an interactive environment, if a new line is not added at the end of the code block, the environment thinks that the following statement belongs to the code block and the following statement is not indented, a syntax error occurs

Menu