Esempio n. 1
0
 def run(self):
     logs.print_info("Oczekiwanie na handshake...")
     msg = self.conn.read()
     Thread(target=self.__pinger).start()
     buff = ""
     while not self.__was_stopped:
         buff += msg
         self.last_seen = datetime.datetime.now()
         if "\n" in msg:
             esc_string = buff[: buff.index("\n")]
             buff = buff[buff.index("\n") + 1 :]
             data = json.loads(un_escape(esc_string))
             logs.print_debug("RECEIVED: %s" % data)
             if "request" in data:
                 Thread(target=partial(self.binder.handle_message, data, self.conn)).start()
         while not self.__is_connected:
             pass
         try:
             msg = self.conn.read()
         except socket.error as e:
             logs.print_warning("socket.error while waiting for server request: %s" % e)
             self.__is_connected = False
         if not msg:
             logs.print_warning("Serwer zamknął połączenie")
             self.__is_connected = False
Esempio n. 2
0
 def __init__(self, binder):
     Thread.__init__(self)
     self.daemon = True
     self.__was_stopped = False
     logs.print_info("Łączenie z serwerem...")
     self.binder = binder
     self.conn = ssl.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM))
     self.binder.set_connection(self.conn)
     self.conn.connect((config.server_host, config.server_port))
     logs.print_info("Połączono z serwerem!")
     self.__is_connected = True
     self.last_seen = datetime.datetime.now()
Esempio n. 3
0
 def reconnect(self):
     logs.print_info("Próba ponownego nawiązania połączenia")
     try:
         self.conn.close()
     except Exception as e:
         logs.print_debug("exception while closing connection in reconnecting: %s" % e)
     self.conn = ssl.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM))
     self.binder.set_connection(self.conn)
     try:
         self.conn.settimeout(10)
         self.conn.connect((config.server_host, config.server_port))
         self.conn.settimeout(None)
         self.__is_connected = True
         self.last_seen = datetime.datetime.now()
         logs.print_info("Nawiązano połączenie ponownie")
     except socket.error as e:
         logs.print_warning("exception while trying to reconnect: %s " % e)
Esempio n. 4
0
def type():
    logs.print_info("Wykonano handshake! Łączenie z serwerem zakończone.")
    return {"request": "ok", "type": "radio", "key": config.server_key, "version": __version__}