def receive():


    while 1:
        try:

            data = s.recv(1024)

            message1 = data.decode("utf-8")
            message = Cipher.decrypt(message1, key=4)


            ChatWindow.config(state = NORMAL)

            ChatWindow.insert(INSERT, "Server : " + message)
            ChatWindow.config(state =DISABLED )

            today = date.today()
            d = today.strftime("%B %d, %Y")
            t1 = datetime.now()
            t2 = t1.strftime("%H:%M:%S")

            cr.execute('''INSERT INTO receive_message (date ,time, receive) VALUES(?,?,?)''', (d, t2, message1))
            db.commit()


        except ConnectionResetError:
            t = messagebox.showinfo("MSG" , "SERVER OFFLINE")
            if t == "ok":
                root.destroy()
示例#2
0
def connection():
    global conn
    s.listen(1)
    conn, address = s.accept()
    if type(address) == tuple:
        ChatWindow.config(state=NORMAL)
        ChatWindow.delete("0.0", END)
        ChatWindow.config(state=DISABLED)

    while 1:
        data = conn.recv(1024)

        message1 = data.decode("utf-8")

        message = Cipher.decrypt(message1, key=4)

        ChatWindow.config(state=NORMAL)

        ChatWindow.insert(INSERT, "client : " + message)
        ChatWindow.config(state=DISABLED)

        today = date.today()
        d = today.strftime("%B %d, %Y")
        t1 = datetime.now()
        t2 = t1.strftime("%H:%M:%S")

        cr.execute(
            '''INSERT INTO receive_message (date ,time, receive) VALUES(?,?,?)''',
            (d, t2, message1))
        db.commit()

    conn.close()