"""
file: service.py
socket service
"""
import socket
import threading
import time
import sys
#浏览器
#创建会话对象
sk = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
#建立链接
sk.connect(('www.baidu.com',80))
#数据传输
sk.send(b'GET / HTTP/1.1\r\nHost: www.baidu.com\r\nConnection: close\r\n\r\n')
#等待数据
data =[]
while True:
re_data = sk.recv(1024)
if re_data:
data.append(re_data)
else:
break
data_str = (b''.join(data)).decode('utf-8')
print(data_str)
文章评论