1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| import socket
def main(): tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) tcp_socket.connect(("127.0.0.1", 8888)) while True: send_content = input("请输入要发送的消息:") if(send_content == "exit"): break tcp_socket.send(send_content.encode("gbk")) recv_data = tcp_socket.recv(1024) print(recv_data.decode("gbk")) tcp_socket.close()
if __name__ == "__main__": main()
|