mardi 11 août 2020

how to solve this error with sockets and Kivy?

i am creating a app with python plese solve this error help

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()

it is my code of a function in my app for students homework here is my server side code of this function

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()

but there is no change in test as we refresh our screen and here is my refresh function

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}'

and code of refresh server side

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,))
    math_des.execute('SELECT * FROM tests WHERE sub = ?', (math,))

    bio_t.execute('SELECT * FROM tests WHERE sub = ?', (bio,))
    bio_d.execute('SELECT * FROM tests WHERE sub = ?', (bio,))
    bio_des.execute('SELECT * FROM tests WHERE sub = ?', (bio,))

    phy_t.execute('SELECT * FROM tests WHERE sub = ?', (phy,))
    phy_d.execute('SELECT * FROM tests WHERE sub = ?', (phy,))
    phy_des.execute('SELECT * FROM tests WHERE sub = ?', (phy,))

    chem_t.execute('SELECT * FROM tests WHERE sub = ?', (chem,))
    chem_d.execute('SELECT * FROM tests WHERE sub = ?', (chem,))
    chem_des.execute('SELECT * FROM tests WHERE sub = ?', (chem,))

    hist_t.execute('SELECT * FROM tests WHERE sub = ?', (hist,))
    hist_d.execute('SELECT * FROM tests WHERE sub = ?', (hist,))
    hist_des.execute('SELECT * FROM tests WHERE sub = ?', (hist,))

    civ_t.execute('SELECT * FROM tests WHERE sub = ?', (civ,))
    civ_d.execute('SELECT * FROM tests WHERE sub = ?', (civ,))
    civ_des.execute('SELECT * FROM tests WHERE sub = ?', (civ,))

    pbi_t.execute('SELECT * FROM tests WHERE sub = ?', (pbi,))
    pbi_d.execute('SELECT * FROM tests WHERE sub = ?', (pbi,))
    pbi_des.execute('SELECT * FROM tests WHERE sub = ?', (pbi,))

    hin_t.execute('SELECT * FROM tests WHERE sub = ?', (hin,))
    hin_d.execute('SELECT * FROM tests WHERE sub = ?', (hin,))
    hin_des.execute('SELECT * FROM tests WHERE sub = ?', (hin,))

    geo_t.execute('SELECT * FROM tests WHERE sub = ?', (geo,))
    geo_d.execute('SELECT * FROM tests WHERE sub = ?', (geo,))
    geo_des.execute('SELECT * FROM tests WHERE sub = ?', (geo,))

    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()

plese help sorry if you think i wrote anything wrong

Aucun commentaire:

Enregistrer un commentaire