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?