1

I have been building a chat application wherein clients connected to the server can have a private chat using Pyro4. Clients register to the server to indicate to everyone that they are available for private chat. Clients may now invite other clients to a private chat session using RMI to exchange messages directly. Below is my class code.

@Pyro4.expose
@Pyro4.behavior(instance_mode="single")
class Messaging(object):

def __init__(self):
    self._connection  = ''
    self._messages_to_server = []
    self._messages_to_client = []


def read_messages_to_server(self):
    try:
        return self._messages_to_server.pop(0)

    except:
        return FALSE

def read_messages_to_client(self):
    try:
        return self._messages_to_client.pop(0)            
    except:
        return FALSE


def send_to_server(self, message):
    self._messages_to_server.append(message)


def send_to_client(self, message):
    self._messages_to_client.append(message)


def set_connection(self, allow):
    self._connection = allow

def get_connection(self):
    return self._connection

Whenever one client invites one client to have a private chat, My code reruns below to creates a uri .

daemon = Pyro4.Daemon()       
uri_str = daemon.register(Messaging())  
daemon.requestLoop()

It works fine, the first time it was run. But for the second request of private chat, it produces an error:

Pyro4.errors.DaemonError: object or class already has a Pyro id

How can I fix it? I want to create different URI for a different pair of clients establishing a private connection?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
alyssaeliyah
  • 2,214
  • 6
  • 33
  • 80
  • 1
    are you sure that is the exact code you're running? Because Pyro puts the Pyro id on the instance (or class) you supply to the register method. If you were calling it with a different object every time, it will not (should not) give this error message. Also, FALSE is a syntax error – Irmen de Jong Oct 22 '18 at 22:10
  • @IrmendeJong -> why does FALSE is a syntax error? It doesn't throw error in my end. – alyssaeliyah Oct 23 '18 at 06:08
  • Then, clearly, you're not showing all of the code you're running. FALSE is an undefined name. It'll give a NameError (sorry, not a SyntaxError) when used as written above. "False" however is the correct builtin symbol, note the case – Irmen de Jong Oct 24 '18 at 19:50

0 Answers0