Beispiel #1
0
 def send_mess(self, id):
     if self.flag == 1:
         SERVER = "127.0.0.1"
         PORT = 8080
         client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         try:
             client.connect((SERVER, PORT))
             print('Connected to chat server', SERVER)
             MESSAGE = "Hello server, World!"
             client.sendall(bytes(MESSAGE, 'UTF-8'))
             conOb = Conn()
             conOb.open()
             self.show_friend(id)
             namefr = input("Nhap ten ban be: ")
             id2 = conOb.tran_name_to_id(namefr)
             if id2 > 0:
                 try:
                     sta = 1
                     localtime = time.asctime(time.localtime(time.time()))
                     seconds = time.time()
                     while True:
                         threading.Thread(target=receive, args=(client,)).start()
                         print_lock.acquire()
                         mess = input("Nhap tin nhan:")
                         client.sendall(bytes(mess, 'UTF-8'))
                         #conOb.write_mess(int(id), int(id2), str(mess), str(localtime), int(sta), float(seconds))
                         print_lock.release()
                     client.close()
                     conOb.show_mess_detail(id, id2)
                     print("gui thanh cong")
                 except EOFError:
                     pass
             else:
                 print("Tai khoan khong ton tai.")
         except:
             conOb = Conn()
             conOb.open()
             self.show_friend(id)
             namefr = input("Nhap ten ban be: ")
             id2 = conOb.tran_name_to_id(namefr)
             if id2 > 0:
                 try:
                     sta = 1
                     localtime = time.asctime(time.localtime(time.time()))
                     seconds = time.time()
                     mess = input("Nhap tin nhan:")
                     conOb.write_mess(int(id), int(id2), str(mess), str(localtime), int(sta), float(seconds))
                     conOb.show_mess_detail(id, id2)
                     print("gui thanh cong")
                 except EOFError:
                     pass
             else:
                 print("Tai khoan khong ton tai.")
Beispiel #2
0
 def show_friend(self, id):
     if self.flag:
         conOb = Conn()
         conOb.open()
         conOb.show_friend(id)
     else:
         print("Ban chua dang nhap\n")
Beispiel #3
0
 def show_mess_detail(self, id1):
     if self.flag ==1:
         frien = input("Chon nguoi dung: ")
         conOb = Conn()
         conOb.open()
         id2 = conOb.tran_name_to_id(frien)
         if id2 > 0:
             conOb.show_mess_detail(id1, id2)
         else:
             print("----Tai khoan khong ton tai----\n")
Beispiel #4
0
 def sing_up(self):
     print("-------cac thong tin de dang ky!-------")
     username = input("user: "******"pass: "******"city: ")
     conObj = Conn()
     conObj.open()
     with conObj.con:
         if conObj.check_city(city) == 0:
             conObj.write_to_city(city, )
         id = conObj.tran_city_to_id(city, )
         conObj.sing_up(username, password, id)
Beispiel #5
0
 def block(self, id1):
     if self.flag == 1:
         conOb = Conn()
         conOb.open()
         self.show_friend(id)
         namefr = input("Nhap ten ban be: ")
         id2 = conOb.tran_name_to_id(namefr)
         if id2 > 0:
             conOb.block(id1, id2)
             conOb.show_friend(id1)
         else:
             print("Tai khoan khong ton tai.")
Beispiel #6
0
 def sing_in(self):
     username = input("username: "******"password: "******"Sign in fail!")
             self.flag = 0
Beispiel #7
0
 def add_friend(self, id1):
     if self.flag == 1:
         newfr = input("Nhap ten nguoi ban muon them: ")
         conOb = Conn()
         conOb.open()
         id2 = conOb.tran_name_to_id(newfr)
         if id2 > 0:
             if conOb.check_block(id1, id2) == 0 and conOb.check_friend(id1, id2) == 0:
                 conOb.write_to_friend(id1, id2)
                 conOb.show_friend(id1)
             else:
                 print("You were blocked by her  or You was friend")
         else:
             print("Tai khoan khong ton tai")
     else:
         print("Ban chua dang nhap")
Beispiel #8
0
 def send_socket(self, id):
     if self.flag == 1:
         SERVER = "127.0.1.1"
         PORT = 8080
         uname = self.username
         client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         try:
             client.connect((SERVER, PORT))
             print('Connected to chat server', SERVER)
             client.send(uname.encode('ascii'))
             threading.Thread(target=User.receiveMsg, args=(self, client,)).start()
             while self.clientRunning:
                 tempMsg = input()
                 msg = uname + '>>' + tempMsg
                 if '**quit' in msg:
                     self.clientRunning = False
                     client.send('**quit'.encode('ascii'))
                 else:
                     client.send(msg.encode('ascii'))
         except:
             conOb = Conn()
             conOb.open()
             self.show_friend(id)
             namefr = input("Nhap ten ban be: ")
             id2 = conOb.tran_name_to_id(namefr)
             if id2 > 0:
                 try:
                     sta = 1
                     localtime = time.asctime(time.localtime(time.time()))
                     seconds = time.time()
                     mess = input("Nhap tin nhan:")
                     conOb.write_mess(int(id), int(id2), str(mess), str(localtime), int(sta), float(seconds))
                     conOb.show_mess_detail(id, id2)
                     print("gui thanh cong")
                 except EOFError:
                     pass
             else:
                 print("Tai khoan khong ton tai.")
Beispiel #9
0
 def show_mess(self, id):
     if self.flag == 1:
         conOb = Conn()
         conOb.open()
         conOb.select_mess(id)