effect:
. 1 Import Socket 2 . 3 . 4 DEF main (): . 5 the while True: . 6 # 1. Create a socket tcp . 7 TCP_SOCKET = socket.socket (socket.AF_INET, socket.SOCK_STREAM) . 8 . 9 # 2. Connection Server 10 tcp_socket.connect (( ' 192.168.2.100 ' , 7788 )) . 11 12 is # 3. transmission data 13 is (the send_data iNPUT = " data to be transmitted enter: " ) 14 tcp_socket.send (send_data.encode ( ' GBK' )) 15 # 4. Close the socket 16 tcp_socket.close () . 17 IF the send_data == ' Exit ' : 18 is BREAK . 19 20 is 21 is IF the __name__ == ' __main__ ' : 22 is main ()