def main(): try: Pyro4.config.COMMTIMEOUT = 0 name_server = Pyro4.locateNS() daemon = Pyro4.Daemon() server = Server() uri = daemon.register(server) name_server.register(server.server_name, uri, safe=True) fe_uri = Pyro4.resolve('PYRONAME:Front_End_Server') Front_End = Pyro4.Proxy(fe_uri) Front_End.registerServers(server) server.front_end = Front_End print("Server {} Online".format(server.server_name)) daemon.requestLoop() except Pyro4.errors.NamingError: print("Error: Could not register Server to Front End")
self.logged_in = not response self.username = None print("You are logged out!") except Pyro4.errors.TimeoutError: print("Error: Request Timed Out!") def getUsers(self): try: response = self.front_end_server.getUsers() response = json.loads(response) if "Error" in response.keys(): print("Error: ", response["Error"]) return # print logged in users on console for user in response["Success"]: print("{}".format(user)) except Pyro4.errors.TimeoutError: print("Error: Request Timed Out!") try: Pyro4.config.COMMTIMEOUT = 0 uri = Pyro4.resolve("PYRONAME:Front_End_Server") front_end_server = Pyro4.Proxy(uri) # set timeout to front end to 5 seconds front_end_server._pyroTimeout = 5 client = Client(front_end_server) except Pyro4.errors.NamingError: print("Error: Could not connect to Front End Server!")
import Pyro4 import socket import time def getIP(): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('8.8.8.8', 0)) return s.getsockname()[0] def getHostName(): return socket.gethostname() try: uri = Pyro4.resolve("PYRONAME:heartbeats") HBobj = Pyro4.Proxy(uri) except: print('Something went wrong') report = {'host-name': getHostName(), 'ip': getIP()} while (1): print(HBobj.updateStatus(report)) time.sleep(5)
print('Invalid input! Enter Y to continue or N to quit\n') if repeat == 'Y': self.get_request() if repeat in ['N', 'QUIT']: print('Goodbye!') return except InvalidUserError as error: print('ERROR: %s' % error.message) self.get_request(operation=operation, movie=movie) return except InvalidMovieError as error: print('ERROR: %s' % error.message) self.get_request(operation=operation) return except CommunicationError as error: if isinstance(error, ConnectionClosedError): print('ERROR: Server closed the connection') elif isinstance(error, CommunicationError): print('ERROR: Cannot communicate with the server') return if __name__ == '__main__': try: CLIENT = Client() URI = Pyro4.resolve("PYRONAME:front_end_server") CLIENT.front_end = Pyro4.Proxy(URI) CLIENT.get_request() except NamingError: print('Make sure that service is running first!')