Exemple #1
0
 def processVote(self):
     # if length is three it checks for the commit and then send accordingly.
     if len(self.votes) == 3:
         commit = True
         for i in self.votes:
             if i == 'ABORT':
                 commit = False
         # if commit then send global_commit to server and then server broadcast it.
         if commit:
             glocal_commit = "GLOBAL_COMMIT"
             f = open('coordinator.txt', 'a+')
             f.write(self.string_to_wtite + '\n')
             f.close()
             self.voteResult = glocal_commit
             self.msg_list.insert(tk.END, glocal_commit)
             encoded_msg = ClientHelper().encodemessage(glocal_commit)
             self.network_thread.send_to_server(encoded_msg)
         # if aborts then send global_abort to server and then server broadcast it.
         else:
             glocal_abort = "GLOBAL_ABORT"
             self.voteResult = glocal_abort
             self.msg_list.insert(tk.END, glocal_abort)
             encoded_msg = ClientHelper().encodemessage(glocal_abort)
             self.network_thread.send_to_server(encoded_msg)
         self.votes = []
def on_closing():
    """This function is to be called when the window is closed."""
    # ask to close the application.
    if tkinter.messagebox.askokcancel("Quit", "Do you really wish to quit?"):
        top.destroy()
        encoded_message = ClientHelper().encodemessage('has left the chat.')
        client_socket.send(encoded_message.encode())
        client_socket.close()
    else:
        pass
def send(event=None):  # event is passed by binders.
    """Handles sending of messages."""
    msg = my_msg.get()
    my_msg.set("")  # Clears input field
    encoded_message = ClientHelper().encodemessage(msg)
    client_socket.send(encoded_message.encode())
    if msg == "quit":
        client_socket.close()
        top.destroy()
        top.quit()
Exemple #4
0
 def abort(self):
     abort_message = "ABORT"
     # append to the screen of tkinter.
     self.msg_list.insert(tk.END, abort_message)
     # encode message
     aborted_message = ClientHelper().encodemessage(abort_message)
     # send message to server.
     self.network_thread.send_to_server(aborted_message)
Exemple #5
0
    def timeout(self):

        if not self.voteResult:
            glocal_abort = "GLOBAL_ABORT"
            self.voteResult = glocal_abort
            self.msg_list.insert(tk.END, glocal_abort)
            encoded_msg = ClientHelper().encodemessage(glocal_abort)
            self.network_thread.send_to_server(encoded_msg)
            self.votes = []
Exemple #6
0
 def commit(self):
     commit_message = "COMMIT"
     # self.string = commit_message
     # append to the screen of tkinter.
     f = open('client.txt', 'a+')
     f.write(self.string_to_commit + '\n')
     f.close()
     self.msg_list.insert(tk.END, commit_message)
     # encode message
     commited_message = ClientHelper().encodemessage(commit_message)
     # send message to server.
     self.network_thread.send_to_server(commited_message)
Exemple #7
0
 def send(self, event=None):
     # take a string message.
     string = self.my_msg.get()
     self.string_to_wtite = string
     # encode dtring in HTTP format.
     encoded_msg = ClientHelper().encodemessage(string)
     # print('encoded message from client: ', encoded_msg)
     # add at the end of the chatbox.
     self.msg_list.insert(tk.END, string)
     # print('type of connect.client_socket.send(encoded_msg.encode())',tcpClientA.send(encoded_msg.encode()))
     self.network_thread.send_to_server(encoded_msg)
     Timer(CLIENT_TIME_OUT, self.timeout).start()