我有一台将数据发送到端口的服务器。在python中,如何创建连接到该套接字的脚本,并在本地保存数据流?
答案 0 :(得分:9)
通过简单的客户端套接字程序?
import socket
HOST = 'yourhost' # The remote host
PORT = 101 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
data = s.recv(1024)
s.close()
with open('yourfile','w') as f:
f.write(data)
进一步的帮助here.