import socket
host = "localhost"
port = 50001
comms_socket = socket.socket()
comms_socket.bind((host, port))
comms_socket.listen(10)
connection, address = comms_socket.accept()
while True:
print(connection.recv(4609).decode("UTF-8"))
result_data = input("Reply:")
connection.send(bytes(result_data, "UTF-8"))
以上为server端的代码
客户端的代码
import socket
host = "localhost"
port = 50001
comms_socket = socket.socket()
comms_socket.connect((host, port))
while True:
send_data = input("request_data:")
comms_socket.send(bytes(send_data, "UTF-8"))
print(comms_socket.recv(4609).decode("UTF-8"))