TCPclient.py
import socket
target_host="www.baidu.com"target_port=80
#创建一个客户端,socket.AF_INET是指用IPv4地址,socket.SOCK_STREAM指TCP
client=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
#链接服务端
client.connect((target_host,target_port))
#发送请求
client.send("GET / HTTP/1.1\r\nHost:baidu.com\r\n\r\n")
#接受数据,4096是指准备的缓存,一般为4K
respose=client.recv(4096)
#打印数据
print respose
print "over"