示例#1
0
 def send_message(self, msg):
     msg = ' '.join(map(str, msg))
     msg = msg + " Ø"
     try:
         msg = msg.encode('ISO-8859-1')
         self.s.send(msg)
     except UnicodeEncodeError:
         ExternalWindows.show_error_box("Invalid character!")
示例#2
0
    def talk_message(self):
        msg = self.e1.get()

        if ("Ø" in msg):
            self.e1.delete(0, 'end')
            ExternalWindows.show_error_box("Invalid Ø character")
            return None
        self.e1.delete(0, 'end')
        msg = ("TA", self.my_connexion.ID, msg)
        self.my_connexion.send_message(msg)
示例#3
0
 def load(self):
     filename = askopenfilename()
     try:
         with open(filename, 'rb') as file:
             greeting = pickle.load(file)
             if (greeting == b"Y"):
                 loaded_logs = pickle.load(file)
                 for key in loaded_logs:
                     self.my_connexion.send_message(loaded_logs[key])
             else:
                 ExternalWindows.show_error_box("Invalid pickle file")
     except FileNotFoundError:
         pass
     except pickle.UnpicklingError:
         ExternalWindows.show_error_box("Wrong File Type")
示例#4
0
 def text_draw(self):
     if None not in (self.x1_line_pt, self.y1_line_pt):
         # Show all fonts available
         self.text = ExternalWindows.return_text()
         msg = ('T', self.text, self.x1_line_pt, self.y1_line_pt,
                self.color, self.ID)
         self.send_message(msg)
示例#5
0
 def run(self):
     while True:
         try:
             msg = self.receive_message()
             if( msg[0] in ['O', 'C', 'L', 'R', 'S', 'E', 'D', 'Z', 'T', 'DR']):
                 self.draw_from_message(msg)
                 self.append_to_Logs(msg)
             elif( msg[0] in ['P', 'A', 'RE']):
                 self.user_communication(msg)
                 self.update_connected_user()
             elif( msg[0] in ['TA'] ):
                 self.print_message(msg)
         except ValueError:
             pass
         except IndexError:
             pass
         except ConnectionResetError:
             ExternalWindows.show_error_box("Server down please save your work")
             self.save()
             self.myWhiteBoard.destroy()
示例#6
0
    def __init__(self):
        ExternalWindows.getValuesFromUser()
        self.host = ExternalWindows.return_ip()
        self.port = ExternalWindows.return_port()

        try:
            self.s = socket.socket()
            self.s.connect((self.host, self.port))
            data = self.s.recv(3).decode()
            if data == 'HLO':
                print('[Network]Connection with %s:%s established.' %
                      (self.host, self.port))

            data = self.s.recv(1024).decode()
            UserNames = data.split()

            while True:
                ExternalWindows.get_nickname_from_user()
                self.ID = ExternalWindows.return_nickname()
                if (self.ID in UserNames):
                    ExternalWindows.show_error_box("User name is taken")
                    continue
                break

            self.s.sendall(self.ID.encode())
            print("Received ID is : " + self.ID)
        except:
            ExternalWindows.show_error_box("Could not connect to server")
            exit()
示例#7
0
 def get_text_from_user(self):
     self.drawing_tool = 'text'
     ExternalWindows.get_text_from_user()
示例#8
0
    def __init__(self):
        ExternalWindows.getValuesFromUser()
        self._host = ExternalWindows.return_ip()
        self._port = ExternalWindows.return_port()

        # Here we attempt to establish a connection
        # We open a socket in the given port and IP
        # And start by checking to see if we received a greeting 'HLO'
        # Afterwards the server will send a list with all the names of the connected users
        # This is done to avoid repeating names when creating a new user
        # After the id has been chosen it responds to the server so it can add to the list of clients
        try:
            self.s = socket.socket()
            self.s.connect((self._host, self._port))
            data = self.s.recv(3).decode()
            if data == 'HLO':
                print('[Network]Connection with %s:%s established.' %
                      (self._host, self._port))

            data = self.s.recv(1024).decode()
            UserNames = data.split()

            while True:
                ExternalWindows.get_nickname_from_user()
                self._ID = ExternalWindows.return_nickname()
                if (self._ID in UserNames):
                    ExternalWindows.show_error_box("User name is taken")
                    continue
                break

            self.s.sendall(self._ID.encode())
            print("Received ID is : " + self._ID)
        except SystemExit:
            exit()
        except:
            ExternalWindows.show_error_box("Could not connect to server")
            raise Exception("Connection Failed")