gpt4 book ai didi

python - python socket-如何将流保存到文件

转载 作者:行者123 更新时间:2023-12-03 11:50:29 25 4
gpt4 key购买 nike

我有一台将数据发送到端口的服务器。在python中,如何创建连接到该套接字的脚本,并在本地保存数据流?

最佳答案

通过一个简单的客户端套接字程序?

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.

关于python - python socket-如何将流保存到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6474817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com