'''
be based on socket Realized TCP client
'''
import socket
# establish socket object
# Parameter 1 indicates IP Address type (AF_INET by IPV4,AF_INET6 by IPV6), Parameter 2 indicates the type of connection (SOCK_STREAM Express TCP form ,SOCK_DGRAM Express UDP form )
client_socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM) # representative (ipv4,TCP)
# Connect to server ( Fill target in tuple ip Address and port number )
client_socket.connect(('127.0.0.1',7777))
# Prepare the data , Need to convert to binary data ,encode() The local string encoding format is filled in ,mac、linux fill utf-8
data='hello'.encode('gbk')
# Send data to the server
client_socket.send(data)
# receive data , You must specify the size of the received data , Unit byte , Maximum 4096, namely 4k
recv_data=client_socket.recv(1024)
# The received data shall be processed decode() decode , Fill in whatever code you use when sending
recv_data=recv_data.decode('gbk')
print(recv_data)
# Close the connection
client_socket.close()