当我单击按钮时,它将连接到我的服务器以获取文件,但是在收到文件网页后没有响应吗?
from socket import *
from tkinter import *
import re
import tkinter.messagebox
from tkinter import filedialog
def file():
s = socket(AF_INET,SOCK_DGRAM)
host ="192.168.2.199"
port = 9999
buf =4096
addr = (host,port)
file_name="csr"
ip = re.compile('(([2][5][0-5]\.)|([2][0-4][0-9]\.)|([0-1]?[0-9]?[0-9]\.)){3}'
+'(([2][5][0-5])|([2][0-4][0-9])|([0-1]?[0-9]?[0-9]))')
s.connect(addr)
s.send(file_name.encode())
data,addr = s.recvfrom(buf)
f = open(data.strip(),'wb')
print("File Opened")
data,addr = s.recvfrom(buf)
while True:
print('receiving data...')
data = s.recv(1024)
print('data=%s',(data))
if not data:
break
# write data to a file
f.write(data)
f.close()
print('Successfully get the file')
s.close()
print('connection closed')
window=Tk()
window.geometry('100x100')
Button(window,text=" \t getfile\t ",command=file).pack()
window.mainloop()
我已经尝试过这段代码,但是每次没有响应。
完成按钮单击事件后,它将转到从服务器获取csv
文件的功能。收到文件后,网页无响应,我必须关闭它,然后再次重新打开它。