编写一个简单的TCP客户端
import socket
from urllib import request
target_host = "www.xxx.com"
target_port = 8080
# 链接一个socket对象
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# 链接客户端
client.connect((target_host, target_port))
# 发送一些数据
request = "GET / HTTP/1.1\r\nHost:xxx.com:8080\r\n\r\n"
client.send(request.encode('utf-8'))
# 接收一些数据
response = client.recv(4096)
print(response.decode('utf-8'))