文件接收端:
import socketsocket
sk = socket.socket()ui
ip_port = ("ip", 9999)code
sk.bind(ip_port)server
sk.listen(5)ip
while True:
conn, address = sk.accept()
while True:
with open(r"file1", "ab") as f:
data = conn.recv(1024)
if data == b'quit':
break
f.write(data)
conn.send('success'.encode())it
print("文件接收成功")import
sk.close()file
文件發送端:
import socketim
sk = socket.socket()文件
ip_port = ("ip", 9999)
sk.connect(ip_port)
with open('D:\Python\socket\socket_server.py', 'rb') as f:
for i in f:
sk.send(i)
data = sk.recv(1024)
if data != b'success':
break
sk.send('quit'.encode())