我正在开发一个基于Python套接字的文件传输脚本。服务器可以有10个客户机连接到它,所有的发送文件。问题是,它只发送一个名为'libroR.pdf文件,如果可能,我希望用户能够指定要发送到服务器的自定义文件的名称和位置。如果可能的话,我还希望能够为客户机指定一个自定义主机名以进行连接。在
服务器:
import socket
import sys
s = socket.socket()
s.bind(("localhost",9999))
s.listen(10) # Acepta hasta 10 conexiones entrantes.
while True:
sc, address = s.accept()
print address
i=1
f = open('file_'+ str(i)+".pdf",'wb') #open in binary
i=i+1
while (True):
# recibimos y escribimos en el fichero
l = sc.recv(1024)
while (l):
f.write(l)
l = sc.recv(1024)
f.close()
sc.close()
s.close()
客户:
^{pr2}$谢谢,肖恩。:)
试试这个:
相关问题 更多 >
编程相关推荐