hellobabygogo 2020-04-07
效果:
import socket def main(): while True: # 1.创建tcp套接字 tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # 2.连接服务器 tcp_socket.connect((‘192.168.2.100‘, 7788)) # 3.发送数据 send_data = input("请输入要发送的数据:") tcp_socket.send(send_data.encode(‘gbk‘)) # 4.关闭套接字 tcp_socket.close() if send_data == ‘exit‘: break if __name__ == ‘__main__‘: main()