如何解决如何使用套接字和Kivy解决此错误?
我正在使用python plese创建一个应用程序来解决此错误 帮助
z = socket.socket()
server_host = 'your ip'
port = 1024
z.connect((server_host,port))
z.send('test'.encode())
da = self.root.ids.date.text
time.sleep(.2)
sbj = self.root.ids.subject.text
tim = self.root.ids.time.text
dess = self.root.ids.desss.text
z.send(sbj.encode())
time.sleep(.2)
z.send(tim.encode())
time.sleep(.2)
z.send(da.encode())
time.sleep(.2)
z.send(dess.encode())
z.close()
这是我在我的应用程序中用于学生作业的功能代码,这是此功能在服务器端的代码
sub = z.recv(1024)
sub = sub.decode()
des = z.recv(1024)
des = des.decode()
tim = z.recv(1024)
tim = tim.decode()
date = z.recv(1024)
date = date.decode()
conn = sqlite3.connect('data2.db')
cursor = conn.cursor()
cursor.execute(f"UPDATE tests SET time = ? WHERE sub = ?",(str(tim),str(sub)))
conn.commit()
cursor.execute(f"UPDATE tests SET day = ? WHERE sub = ?",(str(date),str(sub)))
conn.commit()
cursor.execute(f"UPDATE tests SET des = ? WHERE sub = ?",(str(des),str(sub)))
conn.commit()
conn.close()
但是在刷新屏幕时测试没有变化 这是我的刷新功能
z = socket.socket()
server_host = 'your ip address'
port = 1024
z.connect((server_host,port))
z.send('refresh'.encode())
math_t = (z.recv(1024).decode('utf-8'))
math_d = (z.recv(1024).decode('utf-8'))
math_des = (z.recv(1024).decode('utf-8'))
bio_t = (z.recv(1024).decode('utf-8'))
bio_d = (z.recv(1024).decode('utf-8'))
bio_des = (z.recv(1024).decode('utf-8'))
phy_t = (z.recv(1024).decode('utf-8'))
phy_d = (z.recv(1024).decode('utf-8'))
phy_des = (z.recv(1024).decode('utf-8'))
chem_t = (z.recv(1024).decode('utf-8'))
chem_d = (z.recv(1024).decode('utf-8'))
chem_des = (z.recv(1024).decode('utf-8'))
hist_t = (z.recv(1024).decode('utf-8'))
hist_d = (z.recv(1024).decode('utf-8'))
hist_des = (z.recv(1024).decode('utf-8'))
civ_t = (z.recv(1024).decode('utf-8'))
civ_d = (z.recv(1024).decode('utf-8'))
civ_des = (z.recv(1024).decode('utf-8'))
pbi_t = (z.recv(1024).decode('utf-8'))
pbi_d = (z.recv(1024).decode('utf-8'))
pbi_des = (z.recv(1024).decode('utf-8'))
hin_t = (z.recv(1024).decode('utf-8'))
hin_d = (z.recv(1024).decode('utf-8'))
hin_des = (z.recv(1024).decode('utf-8'))
geo_t = (z.recv(1024).decode('utf-8'))
geo_d = (z.recv(1024).decode('utf-8'))
geo_des = (z.recv(1024).decode('utf-8'))
z.close()
math = self.root.ids.math
math.secondary_text = math_des
math.tertiary_text = f'on {math_d},time: {math_t}'
bio = self.root.ids.bio
bio.secondary_text = bio_des
bio.tertiary_text = f'on {bio_d},time: {bio_t}'
chem = self.root.ids.chem
chem.secondary_text = chem_des
chem.tertiary_text = f'on {chem_d},time: {chem_t}'
phy = self.root.ids.phy
phy.secondary_text = phy_des
phy.tertiary_text = f'on {phy_d},time: {phy_t}'
hist = self.root.ids.hist
hist.secondary_text = hist_des
hist.tertiary_text = f'on {hist_d},time: {hist_t}'
civ = self.root.ids.civ
civ.secondary_text = civ_des
civ.tertiary_text = f'on {civ_d},time: {civ_t}'
pbi = self.root.ids.pbi
pbi.secondary_text = pbi_des
pbi.tertiary_text = f'on {pbi_d},time: {pbi_t}'
hin = self.root.ids.hin
hin.secondary_text = hin_des
hin.tertiary_text = f'on {hin_d},time: {hin_t}'
geo = self.root.ids.geo
geo.secondary_text = geo_des
geo.tertiary_text = f'on {geo_d},time: {geo_t}'
和刷新服务器端的代码
conn = sqlite3.connect("data2.db")
math_t = conn.cursor()
math_d = conn.cursor()
math_des = conn.cursor()
bio_t = conn.cursor()
bio_d = conn.cursor()
bio_des = conn.cursor()
phy_t = conn.cursor()
phy_d = conn.cursor()
phy_des = conn.cursor()
chem_t = conn.cursor()
chem_d = conn.cursor()
chem_des = conn.cursor()
hist_t = conn.cursor()
hist_d = conn.cursor()
hist_des = conn.cursor()
civ_t = conn.cursor()
civ_d = conn.cursor()
civ_des = conn.cursor()
pbi_t = conn.cursor()
pbi_d = conn.cursor()
pbi_des = conn.cursor()
hin_t = conn.cursor()
hin_d = conn.cursor()
hin_des = conn.cursor()
geo_t = conn.cursor()
geo_d = conn.cursor()
geo_des = conn.cursor()
math = "math"
bio = "bio"
phy = "phy"
chem = 'chem'
hist = 'hist'
civ = 'civ'
pbi = 'pbi'
hin = 'hin'
geo = 'geo'
math_t.execute('SELECT * FROM tests WHERE sub = ?',(math,))
math_d.execute('SELECT * FROM tests WHERE sub = ?',))
math_des.execute('SELECT * FROM tests WHERE sub = ?',))
bio_t.execute('SELECT * FROM tests WHERE sub = ?',(bio,))
bio_d.execute('SELECT * FROM tests WHERE sub = ?',))
bio_des.execute('SELECT * FROM tests WHERE sub = ?',))
phy_t.execute('SELECT * FROM tests WHERE sub = ?',(phy,))
phy_d.execute('SELECT * FROM tests WHERE sub = ?',))
phy_des.execute('SELECT * FROM tests WHERE sub = ?',))
chem_t.execute('SELECT * FROM tests WHERE sub = ?',(chem,))
chem_d.execute('SELECT * FROM tests WHERE sub = ?',))
chem_des.execute('SELECT * FROM tests WHERE sub = ?',))
hist_t.execute('SELECT * FROM tests WHERE sub = ?',(hist,))
hist_d.execute('SELECT * FROM tests WHERE sub = ?',))
hist_des.execute('SELECT * FROM tests WHERE sub = ?',))
civ_t.execute('SELECT * FROM tests WHERE sub = ?',(civ,))
civ_d.execute('SELECT * FROM tests WHERE sub = ?',))
civ_des.execute('SELECT * FROM tests WHERE sub = ?',))
pbi_t.execute('SELECT * FROM tests WHERE sub = ?',(pbi,))
pbi_d.execute('SELECT * FROM tests WHERE sub = ?',))
pbi_des.execute('SELECT * FROM tests WHERE sub = ?',))
hin_t.execute('SELECT * FROM tests WHERE sub = ?',(hin,))
hin_d.execute('SELECT * FROM tests WHERE sub = ?',))
hin_des.execute('SELECT * FROM tests WHERE sub = ?',))
geo_t.execute('SELECT * FROM tests WHERE sub = ?',(geo,))
geo_d.execute('SELECT * FROM tests WHERE sub = ?',))
geo_des.execute('SELECT * FROM tests WHERE sub = ?',))
z.send(math_t.fetchone()[1].encode())
time.sleep(.2)
z.send(math_d.fetchone()[2].encode())
time.sleep(.2)
z.send(math_des.fetchone()[3].encode())
time.sleep(.2)
z.send(bio_t.fetchone()[1].encode())
time.sleep(.2)
z.send(bio_d.fetchone()[2].encode())
time.sleep(.2)
z.send(bio_des.fetchone()[3].encode())
time.sleep(.2)
z.send(phy_t.fetchone()[1].encode())
time.sleep(.2)
z.send(phy_d.fetchone()[2].encode())
time.sleep(.2)
z.send(phy_des.fetchone()[3].encode())
time.sleep(.2)
z.send(chem_t.fetchone()[1].encode())
time.sleep(.2)
z.send(chem_d.fetchone()[2].encode())
time.sleep(.2)
z.send(chem_des.fetchone()[3].encode())
time.sleep(.2)
z.send(hist_t.fetchone()[1].encode())
time.sleep(.2)
z.send(hist_d.fetchone()[2].encode())
time.sleep(.2)
z.send(hist_des.fetchone()[3].encode())
time.sleep(.2)
z.send(civ_t.fetchone()[1].encode())
time.sleep(.2)
z.send(civ_d.fetchone()[2].encode())
time.sleep(.2)
z.send(civ_des.fetchone()[3].encode())
time.sleep(.2)
z.send(pbi_t.fetchone()[1].encode())
time.sleep(.2)
z.send(pbi_d.fetchone()[2].encode())
time.sleep(.2)
z.send(pbi_des.fetchone()[3].encode())
time.sleep(.2)
z.send(hin_t.fetchone()[1].encode())
time.sleep(.2)
z.send(hin_d.fetchone()[2].encode())
time.sleep(.2)
z.send(hin_des.fetchone()[3].encode())
time.sleep(.2)
z.send(geo_t.fetchone()[1].encode())
time.sleep(.2)
z.send(geo_d.fetchone()[2].encode())
time.sleep(.2)
z.send(geo_des.fetchone()[3].encode())
z.close()
conn.close()
如果您认为我写错了什么,请帮忙
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com(将#修改为@)